0
       $subject= "Citation flow <img src='/static/images/icons/help.png'>
                                </span>
                            </p>
                            <p style='font-size: 150%;'><b>11</b></p>";
           $pattern="/Citation flow[.]+<b>([0-9]+)<\/b>/i";

          preg_match_all($pattern, $subject,$matches,PREG_PATTERN_ORDER);

          print_r($matches);

I want to capture the number 11 inisde the bold tags.. but my regex expression doesnt work.. why?

UPDATE:

I came up with this.. but I am not 100% it is the best solution:

$pattern="/Citation flow[\s\S]*<b>([0-9]+)<\/b>/i";
4
  • 3
    When you say [.]+ you actually mean .+. [.]+ matches a string of dots; the dot is not special inside a character class. Commented Jun 18, 2012 at 12:15
  • I'd strongly recommend using an actual HTML parser, like simpledom - simplehtmldom.sourceforge.net. Commented Jun 18, 2012 at 12:17
  • You seem to be trying to parse HTML with regular expressions. You may want to read stackoverflow.com/a/1732454/110707 Commented Jun 18, 2012 at 12:17
  • I know about simple_html_parse.. but the doc I am trying to scrape hasnt got many unique tags Commented Jun 18, 2012 at 12:22

2 Answers 2

3

Well, it cannot match as Citation flow has a space after it, not an arbitrary number of dots. You probably meant

(?si)Citation flow.+<b>(\d+)</b>
Sign up to request clarification or add additional context in comments.

4 Comments

whats the difference between \d+ and what i did
Don't forget to use /s or (?s).
Dmitry: \d is a shorthand for [0-9].
You can put the s and i options after the trailing delimiter in preg_match. It's just a way of specifying regex options inline.
0

Do you not want

$pattern="/Citation flow[.]+<b>([0-9]+)<\/b>/si"; 

1 Comment

Unlikely, as that would also try matching literal dots.

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.