G*********a 发帖数: 1080 | 1 【 以下文字转载自 Java 讨论区 】
发信人: GreenPapaya (为什么我是我 [请勿置顶]), 信区: Java
标 题: Regular Expression question: how to enumerate all matches?
发信站: BBS 未名空间站 (Tue May 26 07:46:13 2009)
I want to obtain all the possible matches of "a" from aaaaa, that should be:
a
aa
aaa
aaaa
aaaaa
but 'a+' does not do the the job, it only returns the longest match "aaaaa".
how can i get all the possible matches enumerated? Thanks! | m******t 发帖数: 2416 | 2
be:
".
I don't think you can come up with one regex to get them all.
You could construct "a{i}" dynamically where i steps from 1 to 5. Or take
substrings of "aaaaa" and try matching each of them against "a+"
But what exactly are you trying to achieve?
【在 G*********a 的大作中提到】 : 【 以下文字转载自 Java 讨论区 】 : 发信人: GreenPapaya (为什么我是我 [请勿置顶]), 信区: Java : 标 题: Regular Expression question: how to enumerate all matches? : 发信站: BBS 未名空间站 (Tue May 26 07:46:13 2009) : I want to obtain all the possible matches of "a" from aaaaa, that should be: : a : aa : aaa : aaaa : aaaaa
| r*******n 发帖数: 3020 | 3 in vim, you just use the option of g[lobal]
like this.
it will put each matches in a single line,
and then you can move them to the end of file
by this:
be:
". |
|