Pretty straightforward.. I'm new to regex and was wondering how I can perform something like this? Initially I went with:
if (Regex.IsMatch(par, "^[0-9a-zA-Z]+$"))
You seem to be looking for
See the regex demo
^- start of string
[^,\\^]*- zero or more chars other than
$- end of string.
[^...] defines a negated character class that matches any chars but the ones specified in the class. Note that the second
^ inside the brackets is considered a literal caret (while the first one is a part of the negated character class construct).
If you do not allow an empty string, replace
* (zero or more occurrences) with
+ (one or more occurrences).
To further create regexps like this, just put the chars into the negated character class remembering that
- are better escaped to avoid confusion. The
. lose their special meaning, and denote the literal symbols.