The value I'm trying to match to can either be a word OR it can be empty.
I need a regex that will do one of the following:
OR
The non empty string is important because "" is the same as default in my situation.
Is there a regex for this?
Anything that helps point me in the right direction is appreciated.
Java static code analysis: Repeated patterns in regular expressions should not match the empty string.
The word boundary \b matches positions where one side is a word character (usually a letter, digit or underscore—but see below for variations across engines) and the other side is not a word character (for instance, it may be the beginning of the string or a space character).
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
An empty regular expression matches everything.
Sure, the regex is pretty simple:
/^(|default)$/
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