[Novalug] a regex puzzle
Jason Kohles
jkohles@palantir.com
Mon Mar 19 14:45:26 EDT 2012
The reason it works is that X* matches *zero-or-more* X's, and every
position in the string contains zero-or-more X's..
--
Jason Kohles
Palantir Technologies | UNIX Systems Engineer
jkohles@palantir.com | 703.957.5784
On 3/19/12 1:47 PM, "daniel" <daniel@yacg.com> wrote:
I see what it does. Not going to spoil it for anyone who wants to try
it themselves. I'd like to know why.
To help myself understand better I altered the line to read:
$ echo NovaLUG | sed 's/L*/,/g'
and then again to:
$ echo NovaLUG | sed 's/LUG*/,/g'
The results are interesting.
On 03/19/2012 12:08 PM, Jon LaBadie wrote:
> The recent discussions of pattern matching and regular
> expressions brought to mind a favorite puzzle.
>
> Sed can be used to modify strings with its substitute
> command, eg s/existing stuff/new stuff/g. The "g" at
> the end allows sed to change all occurances rather than
> just the first.
>
> For example:
>
> $ echo Novalug | sed 's/lug/LUG'
> NovaLUG
>
> The "existing stuff" part can be a regular expression.
>
> What would be the output of:
>
> echo NovaLUG | sed 's/X*/,/g'
>
> Jon
_______________________________________________
Novalug mailing list
Novalug@calypso.tux.org
http://calypso.tux.org/mailman/listinfo/novalug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4634 bytes
Desc: not available
URL: <https://lists.firemountain.net/pipermail/novalug/attachments/20120319/2f82db50/attachment.p7s>
More information about the Novalug
mailing list