0

I can't find a solution to this problem: I want to match all text between tags and followed by 4 numbers inside ( ).
Exg. I want to match this:

<i>Alien - Resurrection </i> (1997)
<i>Alien - Resurrection </i>(1997)
<i>Alien - Resurrection </i>
(1997)

Now if it founds:

<li> Alien -Resurrection </i> bla bla bla <i> Alien the first one </i> (1991)


It matches the whole string, but i would like it to only match the

<i> Alien the first one </i> (1991)


The strict rule is that after the tag there must 4 digits into brackets ()

My regular expression now looks like this:

/<i>(.*?)<\/i> \(([0-9]*)\)/s
1

1 Answer 1

1

Use anchors..

/^<i>([\s\S]*?)<\/i>\s*\(([0-9]{4})\)$/

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Close, but i think i didn't explain very well. The problem is that now, my regex it matches this:<li> Alien -Resurrection </i> bla bla bla <i> Alien the first one </i> (1991) but i would like it to only match the <i> Alien the first one </i> (1991). The strict rule is that after the </i> tag there must 4 digits into brackets ()
Just remove ^ and $ from the regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.