Since i try to used this regular expression
/names+([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*[A-Za-z0-9])(?!S)/g;
my input that i want is for example:
- name test
- name test-name
- name test-name-2
but when i try to check this input it’s also allowed
- name test-name anytext
what i want is after test-name shouldn’t allowed any whitespaces or characters anymore
5
Answers
Hi maybe try something like
names+([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*[A-Za-z0-9])(?!S)(?! )
I added (?! ) so it means that a space is not allowed after your string
The regular expression for the opposite of whitespace (
s
) isS
:The output of this is "***** ******** ** ****". Note that in Java, backspaces have to be escaped.
To my knowledge it is S (uppercase s). So you can try this:
WIKIPEDIA Article for Regular Expressions
Try this instead:
I have checked the pattern with this test case.
I hope it works for you!
I hope it works for you!