aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Regex Logic " Watch "A Regex Logic " New topic
Author

A Regex Logic

Imran Akbar
Ranch Hand

Joined: May 06, 2010
Posts: 63
Hi

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
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Regex Logic