0

I know this is a very basic question, but I was unable to find an answer. I am trying to use the function validateRegexData in C#. All I am doing is to validate something that's supposed to be alphanumeric. So an example I saw had this:

Regex.IsMatch(inputString, "^[a-zA-Z0-9]+$")

I get only PART of the second parameter: why is there a "+$" sign? Believe me, I tried reading the documentation for an hour, and still didn't get why the parameter starts with "^" and ends with "+$". I saw somewhere that $ indicates that everything up until \n is fair game as validation (meaning inside the first parameter).. but that still doesn't explain the + sign, and I'm not even sure if what I read applies here. Thank you so much in advance.

Not that it makes a difference, but it'll be used in SSIS Sorry - I had used the wrong name, I meant to say "Regex.IsMatch" !!

Thomas Ayoub
  • 27,208
  • 15
  • 85
  • 130
LearnByReading
  • 1,625
  • 3
  • 14
  • 41

1 Answers1

3

This is quite simple:

^[a-zA-Z0-9]+$
^                 <= Start of line
 [a-zA-Z0-9]      <= Any character in the range a to z or A to Z or 0 to 9
            +     <= Repeat previous pattern (here: [a-zA-Z0-9]) one or more time
             $    <= End of line

If you need more explanations in the future about regexes, you can get it explained on Regex101 for example

user4003407
  • 18,919
  • 2
  • 44
  • 58
Thomas Ayoub
  • 27,208
  • 15
  • 85
  • 130