由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Regular Expression question: how to enumerate all matches?
相关主题
How to get a matched String?Re: Regular Expression in Java
java regex pattern question谁用过JAVA1.4带的REGULAR EXPRESSION PACKAGE吗
如何enumerate线程[转载] Java Regular Expression Question //bow !
问一道关于Vector的题Re: [转载] Java Regular Expression Questio
java: use vector to shuffle a deck of Card 问题 (转载)Java Regular Expression Question
如何遍历hashtable里边的每一项?请教String.split的regular expression
generics这样改对马?Java怎麼做matcher呢?
A regular expression question大家都这么处理cross site scripting?
相关话题的讨论汇总
话题: aaaaa话题: matches话题: enumerate话题: expression话题: regular
进入Java版参与讨论
1 (共1页)
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
8
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.
1 (共1页)
进入Java版参与讨论
相关主题
大家都这么处理cross site scripting?java: use vector to shuffle a deck of Card 问题 (转载)
regex急求帮助如何遍历hashtable里边的每一项?
must-have Eclipse plug-insgenerics这样改对马?
regular expression for whitespace in pathA regular expression question
How to get a matched String?Re: Regular Expression in Java
java regex pattern question谁用过JAVA1.4带的REGULAR EXPRESSION PACKAGE吗
如何enumerate线程[转载] Java Regular Expression Question //bow !
问一道关于Vector的题Re: [转载] Java Regular Expression Questio
相关话题的讨论汇总
话题: aaaaa话题: matches话题: enumerate话题: expression话题: regular