Regex: How to match a specific tag name?

RastaLulz

fight teh power
Staff member
May 3, 2010
3,865
3,765
I've ran into an issue with , which doesn't ensure the tag name is an exact match, which results in it seeing mj-image being the same as mj-image-variable, since all it's looking for is <mj-image*.

Here's the specific line of code causing the issue:

I want to the regular expression to ensure an exact match of the tag name, with the following scenarios in mind:
1. No attributes.
2. Has attributes, on the same line.
3. Has attributes, but on a different line.

Here's a regex101:

Here's what you can do to match #2 and #3:
 
Solution
Here's what I was looking for, which covers all of the scenarios I described:
Code:
<mj-image((?:[ \n][^>]*)?)>([^]*?)<\/mj-image>

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,435
1,334
Code:
<mj-image[ \n]?([^>]*)?>([^]*?)<\/mj-image>

Not 100% sure if that'll work, all I did was make the new line and attributes groups optional.
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,865
3,765
Here's what I was looking for, which covers all of the scenarios I described:
Code:
<mj-image((?:[ \n][^>]*)?)>([^]*?)<\/mj-image>

 
Solution

Users who are viewing this thread

Top