• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular expressions in Java  RSS feed

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following requirement.

I have a String that could be of the following forms.
1) /foo/{Id} where {Id} is a number
2) /foo;{SomeString} where {SomeString} is some string.

I need to give an error if the String is not of this form, otherwise i need to get "foo" and "{Id}" or "{SomeString}"

I can try to parse the String but i think Regular expressions should be used for this.

Can anyone direct me as to how regular expressions need to be used in this case.

Regards,

Rahul
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are asking for which classes in Java support Regex- You can have a look at java.util.regex.Pattern and java.util.regex.Matcher classes.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can take a look at the Java RegEx Turorial. It's pretty clear and helpful.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Alan and Mohamed..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!