• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pattern matching

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i need to parse a string and need a good pattern to match conditions any help is appreciated. eg :

imported bottle of perfume
packet of headache pills
bottle of perfume
box of imported chocolates
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, we need to understand what you are trying to match. Having 4 generic phrases is not enough to determine what you are trying to match, and more importantly, what you are trying to *not* match.

Second, regex can also parse. So, if you describe *exactly* what you are trying to match, and then describe exactly how it is to be parsed, we may be able to provide a regex that can parse too.

Henry
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Exactly what do you want?..

Here is some sample code.......

import java.util.regex.Pattern;

public class MainClass {
public static void main(String args[]) {
String statement = "a b c d e f g h i j k l";

String splitPattern = "e|c|a|a|(a b d e)|(b c e)";

Pattern p = Pattern.compile(splitPattern);

String[] tokens = p.split(statement);

for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
}
}

Regards,
Suresh Kumar.K
 
deep rai
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you both Henry and Suresh
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic