2

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.

zed_0xff
  • 32,417
  • 7
  • 53
  • 72
Jova
  • 41
  • 1
  • 1
  • 2
  • 1
    I think you mean position 12 to the end of the line, seeing as an index of 0 is much more common than an index of 1. – jbranchaud Dec 15 '11 at 22:30
  • I said this in my answer, but I think it's worth using a substring function instead of regex. Pretty much all languages have this function. – Platinum Azure Dec 15 '11 at 23:17

3 Answers3

9
/^.{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.

jzila
  • 724
  • 4
  • 11
  • ...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... :) – loretoparisi Jun 04 '18 at 14:25
1
/.{12}(.*)/

Match the first 12 chars, then match the rest.

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

Amadan
  • 191,408
  • 23
  • 240
  • 301
1

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.

Platinum Azure
  • 45,269
  • 12
  • 110
  • 134