Hi everybody,
I'm pretty sure my earlier post got deleted in the system maintenance, so I'm going to repost, just to be sure.
I'm writing a version of a grep program, which can take either a string of words separated by spaces or a string containing punctuation marks. What I need to to is compile a pattern that replaces the spaces with a predefined list of punctuation marks, and then can match any string of punctuation marks in that place.
So, as an example:
Query string: This is a test
Should match: This is a test; This, is--a. test; This: is, a test; or any variant, basically, all the words of the query, in order, with any number of punctuation marks in it.
I was looking at java.util.regex, and this is what I have so far:
String query = args[1];
Pattern pattern = Pattern.compile( query.replaceAll( " ", "[ ,:�()�����\"]+" ) );
Matcher matcher = pattern.matcher( element );
if( matcher.matches() ) {
chapterCounter++;
}
Something about this isn't working, though--I never get matches. Can anyone see where I'm going wrong?
EDIT: I'm realizing that this probably isn't clear, since I haven't gotten responses yet, so I'll try to pare it down to the essentials: Instead of matching a string that contains spaces, I need to match a string of words that can have any number of punctuation marks in place of the simple spaces. The key is that the words are the same, and in the same order.
Thank you!
Jezzica85
Message was edited by:
jezzica85