简体   繁体   中英

Regular expression to match everything between first occurrences of two words, both of which appear more than once

I want to parse this json and pull out everything that appears between the first occurrence of the word feed and the first instance of the word widget_standard .

I figure that this should be easy enough but my regex actually matches everything between the first occurrence of feed and the second occurrence of widget_standard .

What do I have to do to my regex /(feed=http.*widget_standard)/i to only match up to (and including) the end of the first occurrence of the word widget_standard ?

Use the lazy star match .*? like this:

/(feed=http.*?widget_standard)/i

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM