This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training 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

JavaRanch » Java Forums » Java » Java in General
Bookmark "String Pattern Matching In Java" Watch "String Pattern Matching In Java" New topic

String Pattern Matching In Java

Sarika Sukumaran

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

Joined: Sep 21, 2011
Posts: 2409
Sounds like a perfect use case for regular expressions:

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

I agree. Here's the link:
subject: String Pattern Matching In Java