wood burning stoves 2.0*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 41592
    
  55
Using "{1,15}" instead of "{0,15}" would do that. Or is it acceptable if only one of the two groups has digits?


Ping & DNS - my free Android networking tools app
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: 19674
    
  18

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: Regex for a combination of digits and space