Ok sorry this might seem like a dumb question but I cannot figure this thing out :
I am trying to parse a string and simply want to check whether it only contains the following characters : ‘0123456789dD+ ‘
I have tried many things but just can’t get to figure out the right regex to use!
Regex oReg = new Regex(@'[\d dD+]+'); oReg.IsMatch('e4');
will return true even though e is not allowed… I’ve tried many strings, including Regex(‘[1234567890 dD+]+’)…
It always works on Regex Pal but not in C#…
Please advise and again i apologize this seems like a very silly question
Try this:
The
^and$at the beginning and end signify the beginning and end of the input string respectively. Thus between the beginning and then end only the stated characters are allowed. In your example, the regex matches if the string contains one of the characters even if it contains other characters as well.@comments: Thanks, I fixed the missing
+and space.