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.
精彩评论