开发者

POSIX regexp for finding everything between wordX and wordY

开发者 https://www.devze.com 2022-12-28 06:07 出处:网络
I have string as: 开发者_运维问答FOO /some/%string-in.here BAR I would like to get everything between FOO and BAR but NOT including FOO[:space:] and NOT including [:space:]BAR

I have string as:

开发者_运维问答FOO /some/%string-in.here BAR

I would like to get everything between FOO and BAR but NOT including FOO[:space:] and NOT including [:space:]BAR

Any ideas it will be appreciate it.


Can't you just use a capturing group?

/FOO (.+?) BAR/


To get everything between FOO and BAR, except any spaces after FOO or before BAR, use this regex for POSIX ERE:

FOO[[:space:]]*(.*)[[:space:]]*BAR

or for POSIX BRE:

FOO[[:space:]]*\(.*\)[[:space:]]*BAR

Because POSIX only supports greedy quantifiers, this regex captures everything between FOO and the last occurrence of BAR, in case there is more than one BAR.

0

精彩评论

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

关注公众号