Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: [emacs] converting perl regex into elisp regex

by doom (Deacon)
on Sep 18, 2009 at 02:04 UTC ( #796017=note: print w/ replies, xml ) Need Help??


in reply to Re: [emacs] converting perl regex into elisp regex
in thread [emacs] converting perl regex into elisp regex

Some emacs code to start with:

(defun perlish-fix-regexps (regexp) "Simple translation of a perlish REGEXP to an emacs one." (let ( (new-pattern regexp) ) (setq new-pattern (replace-regexp-in-string "(" "\\\\(" new-patter +n)) (setq new-pattern (replace-regexp-in-string ")" "\\\\)" new-patter +n)) (setq new-pattern (replace-regexp-in-string "|" "\\\\|" new-patter +n)) (setq new-pattern (replace-regexp-in-string "\\\\\"" "\"" new-patt +ern)) new-pattern)) (perlish-fix-regexps "(.*?)") (perlish-fix-regexps "(ha|ho)") (perlish-fix-regexps "\"[ \t]*(.*?)[ \t]*\"") (defun perlish-match (string pattern) "Apply the perlish PATTERN to STRING, returns capture from first gro +up of parens." (let ( (emacs-pattern (perlish-fix-regexps pattern)) (found "") ) (if (string-match emacs-pattern string) (setq found (match-string 1 string)) ) )) (perlish-match "ha, ha, ho, ho!" "(ha|ho)" ) (perlish-match " \" quote \" " "\"[ \t]*(.*?)[ \t]*\"")


Comment on Re^2: [emacs] converting perl regex into elisp regex
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://796017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-09-01 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (6 votes), past polls