I am using a regex expression to validate an input. I would like to match the exact strings "spe1" and "spe1.grl".

So far I have written the following code:

'\\b(?!i' + this.stringToIgnore + '\\b)\\w+';

where this.stringToIgnore = 'spe1'

this work if I type:

"spe1 " (note the space)

"spe1."

I would like to have a match as soon as I type:

"spe1" (without the need to add a space or dot at the end)

"spe1.grl" (without the need to add a space or dot at the end)

Thank you for your help

1 Answers

0
Dino On

After palying a bit with an online Regex tool I have find the answer to my own question. I am posting it in case someone needs it:

'\\b(?!' + this.stringToIgnore + '\\b)\\w+';

or

''\\b(?!' + this.stringToIgnore + '|' + this.stringToIgnore.toUpperCase + '\\b)\\w+';

in case the user has the uppercase key on.