开发者

modify regular expression to ignore underscores after question marks

(.[^_]+) 

Matches correctly when there is no underscore, how can I modify this regex to match when there is no underscore only before a question mark ?

i开发者_如何学运维e. ignore any underscores after ?


This will only allow underscores after the question mark:

(.[^_]*(\?.*)?)


.[^_]*?\?.*

Anything except for underscore zero or more times, lazy quantifier (the shortest match), followed by a question mark. Another option:

.[^_\?]*\?.*


Put the question mark itself into your negated character class:

(.[^_?]+)

This will match all characters until it’s either an underscore or a question mark.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜