(.[^_]+)
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 ?
ie. ignore any underscores after ?
(.[^_]+)
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 ?
ie. 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.