Is it possible to make a conditional that does not check part of the string when is not needed?
For example:
Regex:
^[a-zA-Z]+.*#[0-9]+$
Example text:
feature: My name is Oliver #9123
I would like to when the text being:
release: My name is oliver
The same Regex matches both cases not requiring the #9123 for the release prefix, is that possible?
I have tried to use some regex conditionals that I found on google, but didn’t have success.
>Solution :
You could try a logical OR (|) in the regexp:
const tests=["My name is Oliver #9123",
"release: My name is oliver",
"this should fail",
"#12345 another fail"];
tests.forEach(str=>
console.log(str+" - "+(str.match(/^release|[a-zA-Z]+.*#[0-9]+/)?"pass":"fail"))
)