phil
phil

Reputation: 51

Regex to find text immediately following 1st occurrence of a word

Say I'm looking at a stream of a web page, and near the top it says About 367 results etc etc. I would like to get the number (of results) following the word About with a regex. Does anyone have an example? Or a bone-head tutorial for that matter? Thanks.

Upvotes: 1

Views: 115

Answers (2)

Leons
Leons

Reputation: 2674

You can extract the number as follows

About (\d+)

or

About (\d+) results

In both cases the digits will be captured.

Upvotes: 1

Ray Toal
Ray Toal

Reputation: 88378

You'll want to capture the first group in for the regex /\bAbout\s+(\d+)/

Upvotes: 3

Related Questions