Skip to main content

Thread: Help with regular expressions


i'm trying develop better understanding of command line working way through book "the linux command line" schotts, available view here

http://linuxcommand.org/tlcl.php

i'm on section dealing regular expressions on page 262. uses example regular expression "only match lines consisting of groups of 1 or more alphabetic characters separated single spaces:"

code:
^([[:alpha:]]+ ?)+$
as example uses grep command

code:
carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]]+ ?)+$' that
the problem i'm having + command seems not work. same result if leave out

code:
carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]] ?)+$'  that
and want match lines consisting of 1 alphanumeric character followed space. think
code:
^([[:alpha:]]? ?)+$
would job (i've replaced + ?), doesn't

code:
carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]]? ?)+$' that
it still returns line though has more 1 character before space.

weirdly, third quantifier (the first ? in original code) works because if pass line more 1 space
code:
carranty@carranty-desktop ~ $ echo "this  that" | grep -e '^([[:alpha:]]+ ?)+$'  carranty@carranty-desktop ~ $
it doesn't output line. can please me out , explain i'm doing wrong.

ok, above post may little long heres more basic example. want match lines consisting of more 1 character. shouldn't

code:
[[:alpha:]]*
do it?? because isn't working me

code:
carranty@carranty-desktop ~ $ echo "t" | grep -e '[[:alpha:]]*' t


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] Help with regular expressions


Ubuntu

Comments

Popular posts from this blog

Joomal 3.6.3 update error - PHP temporary folder is not set - Joomla! Forum - community, help and support

Upgrade 3.4.8 to 3.5.1 failed "download package failed" - Joomla! Forum - community, help and support

Fatal error during instalation - Joomla! Forum - community, help and support