• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forward slash and Regex  RSS feed

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one help me understand why this method returns false while I expect it to return true



Thanks,
Rajagopal
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe because it isn't checking the second parameter? You can only check for one expression (as far as I know), unless you are using a true regex expression that will fulfill multiple conditions.

But it brings a couple more questions to mind. I would think that would throw a compile time error, because there is no matches method that takes two strings as parameters (at least in the standard API). That leads me to suspect that you are trying to overload the method somehow?

Also, since the title of the thread indicates that you are having an issue finding the second string, have you tried altering your code to just look for that particular string and see if it works?

[ November 29, 2005: Message edited by: C Clites ]
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the method does exist in Tiger (Java 5).

I'm not sure why you think this should match, though. The first argument is the regular expression, and it doesn't contain anything to match the "/" (which is not a special character here.) Remember that the "matches" function tries to match the entire sequence, unlike "find", which matches a subsequence. If your regexp were ".enterprise" then it would match.
 
Chad Clites
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the method does exist in Tiger (Java 5).


Cool.. I was not aware of that. That explains a lot....
/me goes to catch a Tiger
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why you think this should match, though. The first argument is the regular expression, and it doesn't contain anything to match the "/" (which is not a special character here.) Remember that the "matches" function tries to match the entire sequence, unlike "find", which matches a subsequence. If your regexp were ".enterprise" then it would match.


Thanks for the explanation. I'll go back and understand the fundamentals first before I try writing a quick hack with regex the next time

-Rajagopal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!