cl-ppcre icon indicating copy to clipboard operation
cl-ppcre copied to clipboard

Feature request: replace all with register group bind macro

Open mmontone opened this issue 10 years ago • 2 comments

I would like to have a register-group-bind like macro for replacing all the regex occurrences in a string.

It would be something like:

replace-register-groups var-list (regex target-string &key start end sharedp) declaration* statement* => result*

where result* is the replacement of regex matching in target-string with the result of statement*

Does this make sense? I looked for something like this for one of my tasks, but I couldn't find it, apart from regex-replace-all

mmontone avatar Apr 08 '15 12:04 mmontone

Example:

(regex-replace-all "@emph{(.*?)}" "@emph{this} is @emph{emphasized}"
                   (lambda (match text) 
                 (format nil "\\emph{~A}" text))
                   :simple-calls t)

Would be equivalent to:

(register-groups-replace (text) ("@emph{(.*?)}" "@emph{this} is @emph{emphasized}")
    (format nil "\\emph{~A}" text))

mmontone avatar Apr 08 '15 13:04 mmontone

Ok, I could write that macro, but well...just an idea, may make sense to be part of the api, I don't know.

mmontone avatar Apr 08 '15 13:04 mmontone