• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Pattern Matching In Java

 
Sarika Sukumaran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2946
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic