Matthew
Matthew

Reputation: 2246

Ignore First Character in Regex Match

I need to ignore the > in my regular expression in the beginning.

My regular expression:

/(>(.+)(?=<\/a>))/igm

Matches the following:

enter image description here

How do I tell it to ignore the > in the beginning?

Here is the regular expression on regexr.com.

Upvotes: 12

Views: 43086

Answers (2)

Federico Piazza
Federico Piazza

Reputation: 30995

You can use:

.*?>(\w+)<

Regular expression visualization

Here you can check a working example:

Debuggex Demo

Upvotes: 5

Jerry
Jerry

Reputation: 71538

Possible workaround would be to match non > characters:

[^>]+(?=<\/a>)

regex101 demo

Or you take the substring of each of your results in the code itself.

Upvotes: 12

Related Questions