Regex to match from position 13 to end of line

20,582

Solution 1

/^.{12}(.*)$/

The first part will look for the first 12 characters and throw them out, and the second part will group the rest.

Edit: as others have pointed out, you really should just use substring in whatever language you're using. Regex is overkill.

Solution 2

/.{12}(.*)/

Match the first 12 chars, then match the rest.

But I agree with @chance: substr would be better.

Solution 3

I would suggest using a substring function in your language instead.

If you REALLY want a regex solution, in spite of it being about a hundred times slower and more complex than you really need, try something like this:

/.{12}(.*)/

Your desired result is then in the first capture group.

Share:
20,582
Admin
Author by

Admin

Updated on July 17, 2022

Comments

  • Admin
    Admin almost 2 years

    Example strings:

    DFDBDFDFDF21R123
    DFDBDFDFDF21DFD
    

    I need a regex that when run matches ths following:

    R123
    DFD
    

    (no EOL chars)

    Thanks, I hope there is a simple solution that my brain isn't conjuring.

  • loretoparisi
    loretoparisi almost 6 years
    ...but in some specific cases this is the only way. Question is there a way to match the exact start and end char position given ^ and $ with chart start and end values? (I would say no, but with regex you never know... :)