开发者

REGEXP and expressions beginning at start of string or with a separator

开发者 https://www.devze.com 2023-03-12 09:21 出处:网络
I\'d like a REGEXP that only picks up a substring that either starts at the beginning开发者_JS百科 of the string or is preceded by a space or separating character. How does this work?

I'd like a REGEXP that only picks up a substring that either starts at the beginning开发者_JS百科 of the string or is preceded by a space or separating character. How does this work?

For example,

[ _^]Smith

seems to be almost it!


(^|[ _])Smith

^ (start) or one of [ _] followed by Smith

(| is the or operator)


Something like this:

^[ _]?Smith

^- beginning of line
[ _]? - space or underscore 0 or one time

0

精彩评论

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