This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regex for a combination of digits and space Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Regex for a combination of digits and space" Watch "Regex for a combination of digits and space" New topic
Author

Regex for a combination of digits and space

suresh midde
Greenhorn

Joined: Aug 22, 2008
Posts: 25
Hi,

Currently I am working on a regex that should accomodate input as

123456789 (space characters can be multiple) - (space characters can be multiple) 22343434343

So its a hypen separated range, that has to have a combination of digits and space characters (space characters can be zero or any number of times.)


I have got a regex like this

[0-9]{0,15}\\s*-\\s*[0-9]{0,15}\\s*

which works fine for

1. Combination of digits and space
2. Combination of digits alone

and even works for the
Just spaces separated by hypen without any digits like -

I want to avoid such a combination without having any digits

Can any one help me in this regard

Regards
Suresh Midde
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35247
    
    7
Using "{1,15}" instead of "{0,15}" would do that. Or is it acceptable if only one of the two groups has digits?


Android appsImageJ pluginsJava web charts
suresh midde
Greenhorn

Joined: Aug 22, 2008
Posts: 25
Post by: Ulf Dittmer, Sheriff
on Apr 01, 2010 03:09:53
Using "{1,15}" instead of "{0,15}" would do that. Or is it acceptable if only one of the two groups has digits?


Hi Dittmer,

Thanks, its working based on your suggestion.

I just need to avoid the third combination of spaces .

And with the above,it fulfills my requirement.

Regards
Suresh Midde
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

suresh midde wrote:Post by: Ulf Dittmer, Sheriff
on Apr 01, 2010 03:09:53
Using "{1,15}" instead of "{0,15}" would do that. Or is it acceptable if only one of the two groups has digits?

Off-topic: if you use the quote button () it will look like this reply. Doesn't that a) look a lot nicer, and b) save you the effort of copying this information?


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Regex for a combination of digits and space
 
Similar Threads
Regex for backslash
Could you please explain me the meaning of this RegEx?
regular expression validation script
regarding regular expression
Regular expression - help