Length with Or condition

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
selva
Posts: 2
Joined: Sat Nov 03, 2007 4:32 am

Length with Or condition

Post by selva »

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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

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:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
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:
[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}-
selva
Posts: 2
Joined: Sat Nov 03, 2007 4:32 am

Thanks

Post by selva »

Woked like a charm. Thanks a lot.
Post Reply