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 Java 8 in Action this week in the Java 8 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: 39578
    
  27
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 - updated with new look and Ping home screen widget
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: 19556
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex for a combination of digits and space
 
Similar Threads
Regular expression - help
Could you please explain me the meaning of this RegEx?
Regex for backslash
regarding regular expression
regular expression validation script