0

我需要一些帮助来为每个字符(除了前 10 个字符)找到匹配文本字符串的正则表达式。例如,我使用了正则表达式:

.{10} 匹配文本的前 10 个字符

P53236TT0834691

P53236TT08 34691 --> 匹配

但我需要否定结果作为匹配(从 char 11 到 x )有人可以帮助我正确表达吗?

4

3 回答 3

3

使用后视:

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

这将确保在匹配开始之前有 10 个字符,然后将匹配任何内容,直到字符串结束。

于 2013-04-11T09:14:25.977 回答
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.

于 2013-04-11T09:15:21.597 回答
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.

于 2013-04-11T09:16:05.610 回答