File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes regex question, help please! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regex question, help please!" Watch "regex question, help please!" New topic

regex question, help please!

Araad Izadkhah

Joined: Nov 07, 2005
Posts: 15
hey guys,
i need help with the following:
i have a string like this:
<logout reason="user logged out" time="12:32 2006">
and i want to split this string (using split("\\s")), but i want it to give me tokens like this:

"user logged out"

if i use split("\\s\"") it only gives me 1 token:
reason="user logged out" time="12:32 2006"

which is basically back to square one!
thx in advance
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Ah, if only the String were like this:

or this:

it would be easy...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
To elaborate a little bit, I believe Paul is suggesting that if the String represents valid XML (which would necessarily include an end tag), then it would be easiest to use some sort fo XML parser. If it's not valid XML, then I guess you can use regular expressions, but the split() method probably won't help much as the delimiters are too different. I'd recommend using a Pattern and Matcher to find the whole tag, and then another Pattern and Matcher to locate the individual attributes within the tag. This will require some knowledge of regular expressions however. And there are some complications which may not be immediately obvious. If you can use a standard XML parser, that will probably be simpler.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: regex question, help please!
It's not a secret anymore!