null null -4 years ago 109
C# Question

How do I match a string starting at a specific position in the string?

What is the regex for matching a date starting at the 4th position? I want it to return just the date and not the whole match. This is what I have.

^.{4}[2-9][0-9]{3}[0-1][0-9][0-9]{2}
DCSG20170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
DCS120170406090204-FQI-045.TOT 04-FIC-045 00060Y000878279.312500G
DCS120170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G


http://regexr.com/3g0d5

Answer Source

You probably want a non-capturing group:

^(?:.{4})([2-9][0-9]{3}[0-1][0-9][0-9]{2})(?:.*)$

(mouse over the text at: http://regexr.com/3g0db and it will show just one group)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download