Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex with 8 digits 2

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I've just been wondering about to find 8 digit numbers

I've tried
Code:
if [[ $f == @([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) ]]

it's working fine, but looks abit stupid..
then, I've tried
Code:
if [[ $f == @(d\{8\}) ]] or
if [[ $f == @([0-9]\{8\}) ]]

Both above it's not working,
do you guys have any idea about this thanks?
 
Hi

As far as I know, there is no quantifier for given number of matches neither in [tt]bash[/tt] on [tt]ksh[/tt].

In such situations I use [tt]expr[/tt]. Note, that [tt]expr[/tt] is quite slow, so if you need it repeatedly, then better not use it.
Code:
if expr "$f" : '[[:digit:]]\{8\}$' > /dev/null
then
  [gray]# ...[/gray]
fi

Feherke.
 
Ok, thx feherke.

I think I better stick with my current pattern then..

Thanks man
 
what about

if [ ${#f} == 8 ]

Mike

Unix *is* user friendly. It's just selective about who its friends are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top