0

I need some help find a regular expression matching of a text sting for every char expect the first 10. For example, I used the regex:

.{10} to match the first 10 chars of the text

P53236TT0834691

P53236TT08 34691 --> matching

But I need the negative result as matching (from char 11 to x ) Can someone help me with the right expression?

Martlark
  • 13,157
  • 12
  • 78
  • 96
buedi
  • 1

3 Answers3

3

Use a lookbehind:

(?<=^.{10}).*

This will ensure that there are 10 characters before the start of the match and then will match anything until the end of the string.

Joey
  • 330,812
  • 81
  • 665
  • 668
2

In this specific case, you can use:

String pattern = ".{10}(.*)";

The first capturing group will capture all characters in your search string past the 10th. You can trivially extend this to skip any number of characters.

Wug
  • 12,628
  • 4
  • 29
  • 52
2

You could use Groups to match and extract what you need, so the regex would be something like so: ^.{10}(.*)$. This will throw any text coming after the 10th character in a group which you can then access later, as illustrated in this previous SO question.

Community
  • 1
  • 1
npinti
  • 51,070
  • 5
  • 71
  • 94