I am looking to validate an input text against the following pattern in JS/JQuery:
P-1-A100
or
R-5-M42
or
P-10-B99, etc
The text essentially needs to have the following six parts:
Single character P or R followed by
A single '-' followed by
- Any number with 1 or more digits followed by
- A single '-' followed by
- Any alphabet (A-Z) followed by
- Any number with 1 or more digits.
Do I need to take care of escape characters as well. How do I make sure that the input text matches the regular expression.
If it does match, how can I extract the last part (Number)from the input text. I have tried this, but isn't working for me
var isMatch = inputText.match([PR]-\d+-[A-Z]+\d+)
/^[PR]-\d+-[A-Z]+(\d+)$/? Use a capturing group around the subpattern that your are interested in getting from the text.