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:"
as example uses grep commandcode:^([[:alpha:]]+ ?)+$
the problem i'm having + command seems not work. same result if leave outcode:carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]]+ ?)+$' that
and want match lines consisting of 1 alphanumeric character followed space. thinkcode:carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]] ?)+$' that
would job (i've replaced + ?), doesn'tcode:^([[:alpha:]]? ?)+$
it still returns line though has more 1 character before space.code:carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]]? ?)+$' that
weirdly, third quantifier (the first ? in original code) works because if pass line more 1 space
it doesn't output line. can please me out , explain i'm doing wrong.code:carranty@carranty-desktop ~ $ echo "this that" | grep -e '^([[:alpha:]]+ ?)+$' carranty@carranty-desktop ~ $
ok, above post may little long heres more basic example. want match lines consisting of more 1 character. shouldn't
do it?? because isn't working mecode:[[:alpha:]]*
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
Post a Comment