This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex for a combination of digits and space

 
suresh midde
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using "{1,15}" instead of "{0,15}" would do that. Or is it acceptable if only one of the two groups has digits?
 
suresh midde
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic