I am attempting to replace all "begin" and "dur" attribute values in my SVG code with one-tenth of (or ten times) their current values, in order to speed up/slow down animation for testing/debugging purposes.

e.g. replace dur="900s" with dur="90s"

My current regex: \(dur\|begin\)="\([0-9.]+\)s?"

and the replacement: \1="\,(/ \2 10)s"

I receive the error Error evaluating replacement expression: (wrong-type-argument number-or-marker-p #("900" 0 2 (rear-nonsticky display (fontified t face (nxml-attribute-value)) 2 3 (rear-nonsticky (display) fontified t face (nxml-attribute-value))))

1 Answer 1


\2 in your replacement is a string, and it needs to be a number in order to perform the division.

You could convert it to a number using string-to-number, but there's in-built shorthand for treating a capture group as a number; so you just need to change \2 to \#2

  • 3
    just when you think you know all the dark corners of Emacs regexps.... :-)
    – rpluim
    Commented Jul 17, 2019 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.