new to linux/Ubuntu/shell scripting . . .
Toby Kelsey
toby_kelsey at ntlworld.com
Mon Dec 5 23:12:15 UTC 2005
Rachael C. wrote:
> Again, thanks to everyone who has been giving me lot of helpful info. :D
>
> If I want to also look for palindromes that are anywhere between 1 and
> 4 characters in length, what would I do? I am looking at this : (^|\
> )([A-Za-z])([A-Za-z])\3\2($|\.|\ ) and I am not seeing how to break
> it down so I can find palindromes bigger or smaller than 4 character's
> in length. Could someone explain it to me? I am very curious. :)
>
> Thanks!
Firstly I would suggest the matching pattern of
\b([a-zA-Z])([a-zA-Z])\2\1\b
would be better. Do 'man grep' to find out what '\b' does. You could
also use [:alpha:] in there.
Secondly it should be easy to come up with patterns for 1, 2 and 3
letter palindromes based on that one.
Thirldy remember that
this|that|theother
is a pattern which matches 'this', or 'that', or 'theother' and you can
build more complex patterns up from simple ones.
A shell script works like the command-line. You can test commands out
by just typing them interactively at the prompt.
Hope this helps,
Toby
More information about the ubuntu-users
mailing list