Re: Splitting a String with a Regex
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 03 May 2006 21:04:15 GMT
"Jussi Piitulainen" <jpiitula@xxxxxxxxxxxxxxxx> wrote in message news:qotbqufm2h7.fsf@xxxxxxxxxxxxxxxxxxxxxxxxx
Oliver Wong writes:
Danno wrote:Try:
String s = "<?xml...><response
.../><?xml...><response.../><?xml...><response.../>";
String[] tokens = s.split("<\\?xml[.]*>");
for (String token : tokens) {
System.out.println(token);
}
Just a guess, I haven't tried it, so there maybe errors.
Probably won't work. XML is a context-free language, not a
regular language.
It might well work (maybe better with "<[?]xml.*?>" or so) for a
particular kind of input sequence where any <?xml...?> thing only
appears in the beginning of each individual part and nowhere else,
and the ... in any of them doesn't contain >.
Just looping to find each string "<?xml" would then also work.
Oops, I had thought that the regular expression Danno wrote was to get the content of the strings themselves, rather than the delimiters. So actually, Danno's code may probably work, as long as the "[.]*" part isn't greedy, along with the other qualifications you gave.
- Oliver
.
- Follow-Ups:
- Re: Splitting a String with a Regex
- From: Jussi Piitulainen
- Re: Splitting a String with a Regex
- References:
- Re: Splitting a String with a Regex
- From: Oliver Wong
- Re: Splitting a String with a Regex
- From: Jussi Piitulainen
- Re: Splitting a String with a Regex
- Prev by Date: Re: Java collections
- Next by Date: getch in Java
- Previous by thread: Re: Splitting a String with a Regex
- Next by thread: Re: Splitting a String with a Regex
- Index(es):
Relevant Pages
|