cimmer
asked on
google of X results regex pattern for php function preg_match
Im new to regex but not new to the php language. Im looking for a regex pattern that will capture the number of results from "ANY" of the following snippets... Also the content being searched is basically ALL the html from a google search so it needs to be precise and character limited so it doesnt pick up "of about" or "</b>" somewhere later in the content...
CODE:
preg_match($regexpattern,$ content,$r esult);
print $result[1];
EXAMPLES:
CONTENT: Results <b>1</b> - <b>5</b> of <b>5</b> for
RESULT SHOULD BE: 5
CONTENT: Results <b>1</b> - <b>10</b> of about <b>15,000,000</b> for
RESULT SHOULD BE: 15000000
CONTENT: Results <b>1</b> - <b>8</b> of about <b>12,000</b> for
RESULT SHOULD BE: 12000
CONTENT: Results <b>1</b> - <b>8</b> of <b>987</b> for
RESULT SHOULD BE: 987
CODE:
preg_match($regexpattern,$
print $result[1];
EXAMPLES:
CONTENT: Results <b>1</b> - <b>5</b> of <b>5</b> for
RESULT SHOULD BE: 5
CONTENT: Results <b>1</b> - <b>10</b> of about <b>15,000,000</b> for
RESULT SHOULD BE: 15000000
CONTENT: Results <b>1</b> - <b>8</b> of about <b>12,000</b> for
RESULT SHOULD BE: 12000
CONTENT: Results <b>1</b> - <b>8</b> of <b>987</b> for
RESULT SHOULD BE: 987
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
just so both of you guys know... </b> has to be escaped such as <\/b>
obrienslalom's pattern worked great i ended up tweaking it a bit to the following...
preg_match('/Results 1\s*-\s*[\d]{1,2}\s*of[A-Z a-z ]*([\d.,]{1,22}) for/si',$content,$results) ;
to simplify things I did a str_replace on $content to remove <b> tags before using the pattern above.
obrienslalom's pattern worked great i ended up tweaking it a bit to the following...
preg_match('/Results 1\s*-\s*[\d]{1,2}\s*of[A-Z
to simplify things I did a str_replace on $content to remove <b> tags before using the pattern above.
ASKER
dont forget to escape / with a \/
Open in new window