1

I have a string that contains this (and another things):

<b>SINOPSIS:</b><br/> 
Text text text and mooore text...<br/> 

I need a reg-ex to get the text between those first two <br/> tags.

Thanks...

Note: There are more <br/> tags. I need the first occurrence only..

I will be using PHPs preg_match() function.

Jonathan
  • 8,676
  • 20
  • 71
  • 101

2 Answers2

1

this will work, make sure to enable multiline

there are other fancier ways with more checks ect...

edit:

preg_match('!\<br\/\>.+?\<br\/\>!s', $string);

Example 2 (For whitespace before close br),

!\<br\s*/?>.+?\<br\s*/?>!s
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39
Viper_Sb
  • 1,809
  • 14
  • 18
  • Not working. its getting the second pairs of br tags... Or maybe is a multi line problem. How to enable multi line? – Jonathan Jul 28 '10 at 19:49
  • it shouldn't be, can you post more of what you're matching against? as it should be limiting to the FIRST
    and second then stop.
    – Viper_Sb Jul 28 '10 at 19:51
  • Like I said, its maybe a multi line problem. How to enable multi line? – Jonathan Jul 28 '10 at 19:51
  • my bad I put the wrong option in I edited my answer try that one – Viper_Sb Jul 28 '10 at 20:01
  • final version is there in case it helps, I removed the allowance for whitespaces in the
    if you want those it can be done just more complicated
    – Viper_Sb Jul 28 '10 at 20:06
0

Allow me to point you to this brilliant answer by bobince that I stumbled upon when I was tempted to ask a similar question: RegEx match open tags except XHTML self-contained tags

Community
  • 1
  • 1
KSwift87
  • 1,843
  • 5
  • 23
  • 40