aspose file tools*
The moose likes Beginning Java and the fly likes pattern matching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "pattern matching" Watch "pattern matching" New topic
Author

pattern matching

deep rai
Ranch Hand

Joined: Oct 04, 2007
Posts: 56
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
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18113
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
K.Suresh Kumar
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
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

Joined: Oct 04, 2007
Posts: 56
thank you both Henry and Suresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pattern matching
 
Similar Threads
Case Study On Sales Tax Problem
WA #2 ..... word association
coding problem : Mars rovers
coding problem about Sales Taxes
How do i implement OOPs here and wat pattern do i follow