newLISP Fan Club

Forum => newLISP in the real world => Topic started by: reinier maliepaard on July 26, 2013, 03:21:55 AM

Title: Alternative regex solution?
Post by: reinier maliepaard on July 26, 2013, 03:21:55 AM
Hello,



The following code adds to one or more apostroph's a backslash only when the (first) apostroph is preceded by a lowercase letter. My two-step-solution works, but I -newLisp newbie- have doubts on it. Does someone has a better idea? Thanks in advance.



Regards,

Reinier

...............................................................

(setq mcString "C''' g''''' c' A''")



;first step

(replace "([a-g])([']+)" mcString (append $1 "\" $2) 0)



;second step

(while (find "\''" mcString)

(replace "\''" mcString "\'\'")

)



;result is ok:  C''' g''''' c' A''

(println "result:   " mcString)

...............................................................