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
  • 14,208
  • 13
  • 83
  • 99
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
  • 344,408
  • 85
  • 689
  • 683
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,956
  • 4
  • 34
  • 54
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,780
  • 5
  • 72
  • 96