I have problem with matching the html attributes (in a various html tags) with regex. To do so, I use the pattern:
myAttr=\"([^']*)\"
HTML snippet:
<img alt="" src="1-p2.jpg" myAttr="http://example.com" class="alignleft" />
it selects text from the myAttr
the end />
but I need to select the myAttr="..."
("http://example.com")
You have an apostrophe ('
) inside your character class but you wanted a quote ("
).
myAttr=\"([^"]*)\"
That said, you really shouldn't be parsing HTML with regexes. (Sorry to link to that answer again. There are other answers to that question that are more of the "if you know what you are doing..." variety. But it is good to be aware of.)
Note that even if you limit your regexing to just attributes you have a lot to consider:
This is why pre-built, serious parsers are generally called for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With