
thuck
(usa Debian)
Enviado em 06/01/2009 - 19:32h
[0-9]|^$ e ^[0-9]*\$
[0-9]|^$ - que tenha um número ou que tenha uma linha em branco, exemplo:
thuck@thuck:~/programacao/scripts$ echo a3f|egrep '[0-9]|^$'
a3f
thuck@thuck:~/programacao/scripts$ echo 4443|egrep '[0-9]|^$'
4443
thuck@thuck:~/programacao/scripts$ echo aaaa|egrep '[0-9]|^$'
thuck@thuck:~/programacao/scripts$
^[0-9]*\$ - que comece por um número, e tenha N números até terminar, exemplo:
thuck@thuck:~/programacao/scripts$ echo '1'|egrep '^[0-9]*$'
1
thuck@thuck:~/programacao/scripts$ echo 'a1'|egrep '^[0-9]*$'
thuck@thuck:~/programacao/scripts$ echo '33331'|egrep '^[0-9]*$'
33331
Pelo que vc disse, nenhuma das duas resolve seu problema... Creio que o certo seria algo assim:
thuck@thuck:~/programacao/scripts$ echo '333'|egrep '^[0-9]*$|^$'
333
thuck@thuck:~/programacao/scripts$ echo ''|egrep '^[0-9]*$|^$'
thuck@thuck:~/programacao/scripts$ echo 'aaa'|egrep '^[0-9]*$|^$'
thuck@thuck:~/programacao/scripts$ echo '1aaa'|egrep '^[0-9]*$|^$'
thuck@thuck:~/programacao/scripts$ echo '1aaa3'|egrep '^[0-9]*$|^$'
Lembrando que as expressões regulares variam de softwares para softwares.