This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes String Pattern Matching In Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "String Pattern Matching In Java" Watch "String Pattern Matching In Java" New topic
Author

String Pattern Matching In Java

Sarika Sukumaran
Greenhorn

Joined: Oct 20, 2011
Posts: 10
I want to search for a given string pattern in an input sting.
For Eg.

Now I need to search whether the string URL contains "/{item}/". Please help me.
This is an example. Actually I need is check whether the URL contains a string matching "/{a-zA-Z0-9}/".
I need to check this pattern "/{a-zA-Z0-9}/". The pattern should include two slashes and two braces. But the letters can be anything.
For eg: "/{asdFs7f}/", "/{asdfg}/", "/{ASDF}/", "/{23445}/".
Please help me suddenly.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Sounds like a perfect use case for regular expressions: http://download.oracle.com/javase/tutorial/essential/regex/index.html

Something like "/{[a-zA-Z0-9]+}/" should work as the pattern, although you may have to escape a few of the characters.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
The following should be your regex. But as Tim suggested, reading java.util.regex API gives you better understanding why
it is written in such a way. check this link to know why the above poster asked you to escape some characters .
Java regex special characters

 
wood burning stoves
 
subject: String Pattern Matching In Java