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
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
A regular expression followed by an asterisk ( * ) matches zero or more occurrences of the regular expression. If there is any choice, the first matching string in a line is used. A regular expression followed by a plus sign ( + ) matches one or more occurrences of the one-character regular expression.
A zero-width or zero-length match is a regular expression match that does not match any characters. It matches only a position in the string. E.g. the regex \b matches between the 1 and , in 1,2. Zero-lenght matches are often an unintended result of mistakenly making everything optional in a regular expression.
When a character is followed by ? in a regular expression it means to match zero or one instance of the character. So X? matches an 'X' if there is one in the string, but otherwise matches nothing.
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).
[^123456789]+
or
[^1-9]+
I believe this is what you are searching for...
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.
I use this one, starts and ends with zero and contains only zeros.
^[0]+$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With