954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Doubt in Java Regex

HI I am new to regex, could anyone help me in finding the java code using regex:

My input string is : MyData 68309486 Bob

I want to fetch only the digits in sequence like 68309486.

PLz help me!!!

Narayanan87
Newbie Poster
6 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

What you're looking for is called capturing group in java regex.
e.g. for this input: "world cup, football, asia, 2011"
- when you apply this regEx: "^world cup, football, ([^,]*), 2011$"
- then matcher.group(1) is set to "asia"
- when you apply "^world cup, ([^,]*), ([^,]*), 2011$"
- then matcher.group(1) is set to "football" and matcher.group(2) is set to "asia".

See javadoc/google for examples. You need to use Pattern.compile(), Pattern.mathcer() and matcher.group() methods.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: