Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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]*\"")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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 drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-10-04 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?