I have this regular expression
([A-Z], )*
which should match something like
test,
(with a space after the comma)
How to I change the regex expression so that if there are any characters after the space then it doesn't match. For example if I had:
test, test
I'm looking to do something similar to
([A-Z], ~[A-Z])*
Cheers
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
∅, the empty set, is a regular expression. ∅ represent the language with no elements {}.
The most portable regex would be ^[ \t\n]*$ to match an empty string (note that you would need to replace \t and \n with tab and newline accordingly) and [^ \n\t] to match a non-whitespace string.
Use the following regular expression:
^[A-Za-z]*, $
Explanation:
^
matches the start of the string.[A-Za-z]*
matches 0 or more letters (case-insensitive) -- replace *
with +
to require 1 or more letters.,
matches a comma followed by a space.$
matches the end of the string, so if there's anything after the comma and space then the match will fail.As has been mentioned, you should specify which language you're using when you ask a Regex question, since there are many different varieties that have their own idiosyncrasies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With