开发者

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

开发者 https://www.devze.com 2023-03-21 06:13 出处:网络
Say I\'m looking at a stream of a web page, and near the top it says About 367 results etc etc. I w开发者_如何学Could like to get the number (of results) following the word About with a regex. Does an

Say I'm looking at a stream of a web page, and near the top it says About 367 results etc etc. I w开发者_如何学Could 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.


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


You can extract the number as follows

About (\d+)

or

About (\d+) results

In both cases the digits will be captured.

0

精彩评论

暂无评论...
验证码 换一张
取 消