in reply to Re: [emacs] converting perl regex into elisp regex
in thread [emacs] converting perl regex into elisp regex
I know most of this and just experimented a little bit, it's a hack but I thinks it's a good start 8)
Of course substituting \\ as \0 is only a temporarily solution ...
$\="\n"; #--- flags my $flag_interactive; # true => no extra escaping of backslashes my $RE='\w*(a|b|c)\d\('; $RE='\d{2,3}'; print $RE; #--- hide pairs of backslashes $RE=~s#\\\\#\0#g; #--- toggle escaping of 'backslash constructs' my $bsc='(){}|'; $RE=~s#[$bsc]#\\$&#g; # escape them once $RE=~s#\\\\##g; # and erase double-escaping #--- replace character classes my %charclass=( w => 'word' , # TODO: emacs22 already knows \w ??? d => 'digit', s => 'space' ); my $kc=join "|",keys %charclass; $RE=~s#\\($kc)#[[:$charclass{$1}:]]#g; #--- unhide pairs of backslashes $RE=~s#\0#\\\\#g; #--- escape backslashes for elisp string $RE=~s#\\#\\\\#g unless $flag_interactive; print $RE;
Do you see any problems?
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [emacs] converting perl regex into elisp regex
by LanX (Saint) on Sep 18, 2009 at 03:30 UTC | |
by u65 (Chaplain) on Jul 27, 2016 at 15:08 UTC | |
by LanX (Saint) on Jul 27, 2016 at 15:40 UTC |