M
M
Mir_AKM2014-10-23 19:22:44
Java
Mir_AKM, 2014-10-23 19:22:44

Task of the century. How to write a regular expression so that it is not all zeros?

Hello everyone) Need your help
Write a regular expression
condition:
-All digits
-Length 8 or 11
-First two characters - not two zeros
-Third character: 3, 6, 7, 8, 9
-After the third character, not all zeros to the end.
here is what I got
^\d[1-9][36789]\d{5}|[1-9]\d[36789]\d{5}|\d[1-9][36789]\ d{8}|[1-9]\d[36789]\d{8}$
I can't implement the last condition.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mir_AKM, 2014-10-24
@Mir_AKM

^(?!0{2,2})\d{2,2}[36789](?!0*$)(?:\d{5,5}|\d{8,8})$
or so

^\d{2}(?<!0{2})[36789](\d{5}(?<!0{5})|\d{8}(?<!0{8}))$

M
Melkij, 2014-10-23
@melkij

^[1-9]{2}[36789]([1-9]{5}|[1-9]{8})$
?

L
Lolshto, 2014-10-23
@Lol4t0

To highlight numbers of the form "not all zeros of a given length" you can use the solution from SO: stackoverflow.com/a/7865029/774651
This first checks if the string is long 4-6 (?=[0-9]{4.6}$), then skips the 0s 0*and search for a non-zero [1-9] followed by at least 3 digits[0-9]{3,}.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question