| Paste number 40088: | irc parse-message with regex |
| Pasted by: | Cin |
| 1 year, 8 months ago | |
| #lisp | |
| Paste contents: |
| (defmacro array-value-bind (variables array &body body) (let ((array-sym (gensym))) `(let ((,array-sym ,array)) (let (,@(loop for index from 0 to (length variables) for variable in variables collect `(,variable (aref ,array-sym ,index)))) ,@body)))) (defun parse-message (msg) (let* ((letter "a-zA-Z") (digit "0-9") (special "\\[|\\]|\\\\|`|^|\\{|\\}|_") (nickname (format nil "([~A|~A][~A|~A|~A|-]*)" letter special letter digit special)) (host "([a-zA-Z\\/]*)") (prefix (format nil "~A(?:(?:\\!([a-z]*))?\\@~A)?" nickname host)) (command "([A-Z]*)") (message (format nil "(?:\\:~A[ ])?(?:~A)([ ].*)" prefix command))) (multiple-value-bind (string components) (cl-ppcre:scan-to-strings message msg) (declare (ignore string)) (array-value-bind (nickname user host command params) components (format t "User: ~A~%Nick: ~A~%Host: ~A~%Command: ~A~%Params: ~A~%" user nickname host command params))))) |
Annotations for this paste:
| Annotation number 1: | example |
| Pasted by: | Cin |
| 1 year, 8 months ago | |
| Paste contents: |
| CL-USER> (parse-message ":Cin!cin@unaffilited/cin PRIVMSG #bloc") User: cin Nick: Cin Host: unaffilited/cin Command: PRIVMSG Params: #bloc NIL |