|
-
October 20th, 2009, 11:30 PM
#1
About Pattern Matching
Hello All,
I am Abhishek Srivastava. I am trying to do the pattern matching in java program but every time i am getting that pattern matching failure. but i think that my pattern should be pass. here I am putting my string and pattern.
response:@ASLSIM1,54,072,13,SLMVR2913430,24,|Lecture Class|05/09/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|05/09/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|01/09/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|01/09/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|29/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|29/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|25/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|25/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|22/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|22/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|18/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|18/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|15/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|15/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|11/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|11/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|08/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|08/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|04/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|04/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|01/08/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|01/08/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|28/07/2009|09:00-09:30|Al Qusais,QUSAIS,UAE|1|,|Lecture Class|28/07/2009|08:30-09:00|Al Qusais,QUSAIS,UAE|1|,,4C*:
pattern:@ASLSIM1,54,
and the code i am using for pattern matching is
response.matches(pattern)
here response is my string in which i want to find the pattern.
Thanks & Regards
Abhishek
-
October 21st, 2009, 03:48 AM
#2
Re: About Pattern Matching
It's because you are using the wrong method: response.matches(pattern) tries to match the whole response string against the pattern.
You should either change your pattern to match the whole string (just append .* to your pattern) or use the .find() method of a Matcher object instead. Create a Pattern by compiling your pattern, then get the Matcher for your input string and then apply its find method.
That if you are really desperate to use regexps, otherwise in this case I think it would be more efficient to use response.startsWith(pattern).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|