G*********a 发帖数: 1080 | 1 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! |
g*****g 发帖数: 34805 | 2 You should write an algorithm to get all the substring first,
then you can match one by one.
be:
".
【在 G*********a 的大作中提到】 : 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!
|
t**********r 发帖数: 26 | 3 how about a{1,5} ?
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!
【在 G*********a 的大作中提到】 : 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!
|
G*********a 发帖数: 1080 | 4 yi? you have a daughter now?! she is so so so chobby and cute!
nod, since i can't get the regex do the work, i am post-process the returned
string myself.
thanks!
【在 g*****g 的大作中提到】 : You should write an algorithm to get all the substring first, : then you can match one by one. : : be: : ".
|
G*********a 发帖数: 1080 | 5 thanks!
but it returns the longest one still:
aaaaa 0 5
".
【在 t**********r 的大作中提到】 : how about a{1,5} ? : : 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".
|
g**e 发帖数: 6127 | 6 works for me in vi
【在 G*********a 的大作中提到】 : thanks! : but it returns the longest one still: : aaaaa 0 5 : : ".
|
F****n 发帖数: 3271 | 7 If you want to do that in a program, you have to enumerate all substrings
and match them against the regex, because you don't have an index. There are
shortcuts.
returned
【在 G*********a 的大作中提到】 : yi? you have a daughter now?! she is so so so chobby and cute! : nod, since i can't get the regex do the work, i am post-process the returned : string myself. : thanks!
|
G*********a 发帖数: 1080 | |
B*****g 发帖数: 34098 | 9 co-ask,搞不出来
【在 G*********a 的大作中提到】
|
b******e 发帖数: 1861 | 10 How about use group and loop.
import java.util.regex.*;
public class test
{
public static void main(String[] args)
{
Pattern p = Pattern.compile("a(a*)");
String a = "aaaa";
match(a, p);
}
private static void match(String s, Pattern p)
{
Matcher m = p.matcher(s);
while (m.find())
{
System.out.println("found char = " + m.group(0));
match(m.group(1), p);
}
}
} |
a****i 发帖数: 13 | 11 in perl you can do @matched = "aaaaa" =~ m/(?=(a*))/g;
in java you probably can do similar thing by using zero-length look-ahead
and Matcher.find() |
h*********o 发帖数: 62 | 12 @matched = "aaaaa" =~ m/(?=(a*))/g;
is a good one if it works. |