I m looking for a regular postix expression to meet condition
123-990
-123450
4556-00
000695-
total length will be 7. all of them numeric except '-' which can occur once any where.
[0-9\-]{7}
does not cut it pls help
Length with Or condition
Moderators: AmigoJack, bbadmin, helios, MudGuard
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
That definitely works, but it appears that you might have a space at the beginning of your regex. If that's not it, check that you have selected Posix regex syntax:
[0-9-]{7}
And your regex matches strings containing any number of hyphens. To restrict it to matching strings containing exactly one hyphen, use something like
-[0-9]{6}|[0-9]-[0-9]{5}|[0-9]{2}-[0-9]{4}|[0-9]{3}-[0-9]{3}|[0-9]{4}-[0-9]{2}|[0-9]{5}-[0-9]|[0-9]{6}-
But your regex matches any 7-character string containing any number of digits, hyphens and backslashes. Remove the backslash. It isn't a quoting operator inside a character class expression [...]; putting the hyphen at the beginning or end of the class makes it literal:Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
[0-9-]{7}
And your regex matches strings containing any number of hyphens. To restrict it to matching strings containing exactly one hyphen, use something like
-[0-9]{6}|[0-9]-[0-9]{5}|[0-9]{2}-[0-9]{4}|[0-9]{3}-[0-9]{3}|[0-9]{4}-[0-9]{2}|[0-9]{5}-[0-9]|[0-9]{6}-