Regex to match only first 5 positions of a line of text (and nothing more)
-
Want regex to match the following pattern in the first 5 positions (only) of a line of text: position 1............2..............3..............4..............5 s........s or d.....s or d.....s or d.....s or d where s = white space, n = digit The first position is always a white space, and the next 4 positions can be one or more digits. examples: s1234 ss123 sss12 ssss1 s1sss s12ss s123s I tried ^\s+\d+ In an online regex tester, this matches the digits perfectly in the first 5 positions and not any where else on the line. However in a C# program, it is matching not only what is in the first 5 positions of the line, but also any other combinations of s and d on the same line, such as good.......................bad............................bad match.....................match.......................match 12 text text text 53, text text text 123 suggestions? I thought ^\s{1,4}\d{1,4} would narrow things down to the first 5 positions of the line, but that does not work either.