Question : Regular expression riddles

Question about use of regular expressions on the linux command line (bash):

Could someone explain why each of the following behave as they do?
I am quite stumped:

[Ignores the escaped dollar]
tg4 register # echo "$" | sed -r "s/\$/new/"                          
$new

[only works if you double escape the dollar]
tg4 register # echo "$" | sed -r "s/\\$/new/"
new

[works fine with a single escape on * - why is $ above special?]
tg4 register # echo "*" | sed -r "s/\*/new/"  
new

[double escape does same thing - why?]
tg4 register # echo "*" | sed -r "s/\\*/new/"
new

[..wh..what??! it's stuck it on the FRONT!]
tg4 register # echo "*" | sed -r "s/\\\*/new/"
new*

[so does    \\\* == ^   ???]
tg4 register # echo "*" | sed -r "s/^/new/"    
new*

Imagine it is some strange interplay with shell escaping vs perl escaping but can't figure it out.

Answer : Regular expression riddles

I am not a Linux guy, but my guess is this:

perl -p -e 's/\*\$available\*//g'   register.php


The above string conversion in your first example was fore sed, the stream editor.


Random Solutions  
 
programming4us programming4us