开发者

Regex: match any word in a string that starts with "qwe"

开发者 https://www.devze.com 2023-03-24 02:49 出处:网络
Say there are some strings \"abc qwe xyz\" \"qwe abc xyz\" \"abc xyz qwe\" \"abc 123 zyx\" How to write an expression to locate the strings that contain words beginning with \"qwe\"?

Say there are some strings

"abc qwe xyz"
"qwe abc xyz"
"abc xyz qwe"
"abc 123 zyx"

How to write an expression to locate the strings that contain words beginning with "qwe"?

(first 3 lines in our cas开发者_StackOverflow社区e)


Try this:

\bqwe

The \b matches at a word boundary (the start or end of a word).


in perl regex:

/\bqwe/

or, for ABC (case insensitive):

/\babc/i

where \b means 'word boundary'.

0

精彩评论

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