Create a Javascript RegExp to find opening tags in HTML/php template

后端 未结 2 581
温柔的废话
温柔的废话 2021-01-14 05:20

I\'m trying to write a Javascript HTML/php parser which would extract all opening tags from a HTML/php source and return the type of tag and attributes with their values whi

相关标签:
2条回答
  • 2021-01-14 05:40

    Just make sure the last letter before the '>' is not a ?, using [^?]. No lookaheads or -behinds needed.

    <[a-zA-Z](.*?[^?])?>
    

    the parentheses and the last ? is to also match tags like <b>.

    EDIT The solution didn't work for single character tags without attributes. So here is one that does:

    <[a-zA-Z]+(>|.*?[^?]>)
    
    0 讨论(0)
  • 2021-01-14 05:55

    much simpler answer would be <[^/^>]+>

    0 讨论(0)
提交回复
热议问题