How do I match everything on the line but stop when I find a semicolon? If I never find one I should continue matching even if one doesn't exist.
Here is some sample input:
captureme; dontcaptureme
captureme andme andme
captureme andme andme; butnotme
I've tried a lazy quantifier (\w*?); but it won't work if I make the semicolon optional. See my current regex fiddle here.
You can use
^[^;\n]*
With multiline modifier.
See demo
The ^ in a multiline mode will match at the beginning of a line, and the negated character class [^;\n] will match any character but a semi-colon or a newline symbol. * will make the regex engine match those characters 0 or more times. Thus, if you do not want to match emoty lines, use the + quantifier instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With