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
Mat Teo
  • 25
  • 7
  • 2
    Any opportunity to post a link to the greatest answer on SO ever... : http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – CD001 Nov 09 '15 at 15:17

1 Answers1

1

Use anchors..

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

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • Close, but i think i didn't explain very well. The problem is that now, my regex it matches this:
  • Alien -Resurrection bla bla bla Alien the first one (1991) but i would like it to only match the Alien the first one (1991). The strict rule is that after the tag there must 4 digits into brackets ()
  • – Mat Teo Nov 09 '15 at 15:07
  • Just remove ^ and $ from the regex – Alex Blex Nov 09 '15 at 15:13