-2

I have written a regex to match Html tags , if i use on the below tag

<p style="margin-bottom: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Helvetica Neue" ">

it matches till

<p style="margin-bottom: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "

but i want to match till

<p style="margin-bottom: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Helvetica Neue" "

Regex i am using

/^<((?:[a-zA-Z])[\w:-])((?:\s+[\w:-]+(?:\s=\s*(?:(?:"[^"]")|(?:'[^']')|[^>\s]+))?))\s(/?)\s*(>?)/

Can some one correct the above regex to match correctly?

  • 1
    Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Zenoo Feb 27 '19 at 14:03

1 Answers1

0

If you just need to match everything within the tag, the simple regex below should suffice. This would match the start of the tag, followed by any number of characters that are not >

<[^>]*

Sample Regex