I'm trying to get the following conditional logic with regular expression.
if (text starts with +61) {
if (text after +61 is 1800) {
// then match 6 digits after 1800. So, the regex until here should be +611800 and then 6 digits
} else {
// match 9 digits after +61
}
}
I read on how to write conditional regular expressions. But, I'm stuck here with the following regular expression
^\+61((?=1800)\d{6}|\d{9})$
The above regex fails for this, but it has to be successful
- +611800123456 (This has to be success)
And the following text passes the regex test but it has to fail
- +61180012345 (This has to be fail)
Here are my tests in regexr site.
https://regexr.com/5ia2e