I want to match a string with a regular expression in C#. The string can only be preceeded by zero or more whitespaces, no other characters is allowed.
Valid strings are:
"> 5", " > 5"
Invalid strings are:
"1 > 5", "1> 3", ">> 3"
I have this regular expression right now:
"\s*> "
I have also tried "[\s*]> " and "[\s]*> " but with no luck.
This seems like a simple problem, but im fresh to regular expressions and i failed to find an answer elsewhere.
Thanks in advance!
I don’t think you simply meant “start with 0 or more whitespace characters”, because then every string would be valid, including the empty string, because it satisfies at least “start with 0 whitespace”.
Looking at your sample input, perhaps you meant “start with 0 or more whitespace characters, followed by exactly one
>“. In that case, this regex should do it:Replace the second
*with a+if you need to match stuff after the>sign.