tags:

views:

212

answers:

6

Hi, I am looking for a regex pattern that would match several different combinations of zeros such as 00-00-0000 or 0 or 0.0 or 00000

Please help

Thanks!

EDIT:

Well, I have web service that returns me a result set, based on what it returns me I can decide if the result is worth displaying on the page. So if I get either 00-00-0000 or 0 or 00000 I would assume that data was not found, however if it brings back 001 or 000123 or 0356.00 - 1000 or 0.6700, this would be valid.

Hope this clarifies my question

Thanks

+5  A: 

You need to better define what is valid to appear between the zeros. Going from your question, I'll assume you're looking for any number of zeros with any number and grouping of "-" and "." between them....

0([-.]?0+)*

Hope you don't mind, SoapBox:

Based on the question edit, what you are looking for is any string that has non-zero digits in it, so:

[1-9]

or, if the regex engine automatically anchors start and end of string:

.*[1-9].*

may be the better solution.

This is the reverse of the test you asked for but that's a simple matter to change (reverse the sense of the if-statement).

SoapBox
Don't forget to take into account escaping of the '-' and '.' characters since some regex engines assign them special meanings (range and any-char). Still, +1 for a good answer.
paxdiablo
I think most regex engines have . and leading - be literal in a character class.
ysth
That's a bad regex... the "." stands for "any char".
Timothy Khouri
no Timothy. the '.' within [] is taken literally (standing only for itself)
Johannes Schaub - litb
Good point, my bad :)
Timothy Khouri
That will match "0-0.0-000.00" though... I don't know if that's what he wanted.
Timothy Khouri
@Tim, he wanted a way to find interesting numbers, regardless of "punctuation" - that basically means any non-zero digit.
paxdiablo
+1  A: 

Here's the Regex that will match what you have asked for so far. If there is more you want it to match, please specify.

0+((\.0+)|(-0+)*)

That matches all of the examples you asked for.

Timothy Khouri
you are missing a bracket... and it will not match only one zero
Wow, I jacked that up bad... fixing. I think my copy/paste skills are lacking :(
Timothy Khouri
Yeah, that last "0" that was there was supposed to be "shift-zero" ... I should have copy/pasted instead of retyped it.
Timothy Khouri
i think it will still not match only one zero. don't you need parens around the | ?
Johannes Schaub - litb
That'll match a single zero. 0+ <-- that matches 1 or more (1 being ok)... and the second part has * <-- 0 or more. So, yes, it'll work :P
Timothy Khouri
+1  A: 

(00-00-0000|0|0\.0|00000)

aib
Ha, actually quite funny but the question included "such as...", still +1 for making me snort.
paxdiablo
A: 

Well, I have web service that returns me a result set, based on what it returns me I can decide if the result is worth displaying on the page. So if I get either 00-00-0000 or 0 or 00000 I would assume that data was not found, however if it brings back 001 or 000123 or 0356.00 - 1000 or 0.6700, this would be valid.

Hope this clarifies my question

Thanks

Alex
This should be a comment or edit to your original question
Draemon
Alex, I've incorporated this 'answer' into your question - I suggest you delete this answer before it collects more downvotes (for not being a real answer).
paxdiablo
I helped you out, +1 (to -2). Thank Pax. Of course, if you want the peer pressure badge, I'll remove it.
Axeman
A: 
[^123456789]+

or

[^1-9]+

I believe this is what you are searching for...

This seams to have done the trick, thanks!
Alex
You can also use: [^1-9]+
strager
You should be aware that will also match abcdefg
Johannes Schaub - litb
As litb has pointed out this will match all characters excluding the numbers 1-9. Thus including lots of potential typos.
chilltemp
i asked that in a comment to question.there was no reply.
@chilltemp, he wanted a way to find interesting numbers, regardless of "punctuation" - that basically means any non-zero digit. In addition, it's coming from a web service so typos are not really an issue - I'm presuming the data from the web service are okay.
paxdiablo
if he wants to see any nonzero digits, then it is the exact opposite: [1-9] instead.
Johannes Schaub - litb
Don't know why you bothered with the first regex - That's just silly.
Draemon
A: 

You seem to be over-complicating what needs to be done. Rather than looking for different combinations that turn out to be all zeros, why not use a regex that identifies data that you do care about.

Therefore, I suggest you use this: [1-9]

This will match if the string contains any digit that is non-zero, assuming that you're looking at numeric data, of course.

Bill