my dog learned polymorphism
The moose likes Beginning Java and the fly likes A Regex Logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Regex Logic " Watch "A Regex Logic " New topic

A Regex Logic

Imran Akbar
Ranch Hand

Joined: May 06, 2010
Posts: 63

I'm looking to split a string using split or reg expressions, i just need the reg expression which needs to split the below string

i want to split the string as follows

here Delimeter is "*" , when the value contains "* + #" it needs to be generated as a single set.

Whats the pattern i need to use to achieve the above output.

Thanks in Advance.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19911

1) you'll need to escape the * with \ (and again with \ because it's a Java string): \\*. That's because * is a regex meta character.

2) check out negative lookahead and/or negative lookbehind in the Javadocs of java.util.regex.Pattern. Basically you want to split on * except when it follows (and/or precedes?) #. That's exactly what those two techniques are for.

How To Ask Questions How To Answer Questions
wood burning stoves
subject: A Regex Logic