Compose a regular expression

There is such an html code, I’m trying to pull out +13

<span id="c_votes_24649">
  <a href="#" onclick="App.c_votes(24649, 'plus'); return false;">+</a>/<a href="#" onclick="App.c_votes(24649, 'minus'); return false;">−</a>
  (+13)
</span>

did this G (:

preg_match("#<span id=\"c_votes_.+?\">.+?</a>.+?</a>(.*?)</span>#s",$content,$out_raiting);

only it doesn’t work out of the brackets, I tried to escape these brackets like this

preg_match("#<span id=\"c_votes_.+?\">.+?</a>.+?</a>\((.*?)\)</span>#s",$content,$out_raiting);

gives an empty array, I don’t know why


Answer 1, authority 100%

Maybe, of course, I perverted your already perverted regex, but it works ))

#<span id=\"c_votes_.+?\">.+?</a>.+?</a>[\s\(]*(.*?)[\s\)]*</span>#s

At least in this example.

But it will be shorter like this, but you need to check, otherwise you never know what nuances there may be in the text:

#(?<=</a>)[\s\(]+(.*?)[\s\)]*</span>#s

Answer 2, authority 67%

In fact, if you only need to tear out of this text, then the simplest thing is to write

preg_match('/\((+\d{1,})\)/s', $content, $out_raiting)

because “+” and then 2 digits are unique, but if there is a large enough page, then you need to look and it will probably be easier to get to this “+13” through the DOM parser, because most likely the tag “<span>” has a unique id for the page, and “+13” is text in the dom tree.


Answer 3, authority 33%

^.*\((\+\d+)[^<]*</span>$

or so, +number in parentheses before the last closing span

tag