Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Regex Logic

 
Imran Akbar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic