1

Why doesn't this regexp work when I do C-M-%? I need to replace exactly these strings: \text{vars}(\vp) -> |\vp| \text{vars}(\vp') -> |\vp| I don't have anything else of the form \text{vars}*, so I used \\text{vars}(\([:ascii:]+\)) -> |\1| and got Replaced 0 occurrences. What's wrong?

  • 1
    You can use M-x re-builder to test complicated regexps – npostavs Jul 31 '15 at 7:39
5

Character classes need to be used within a character alternative. i.e.

[[:ascii:]]

If you just have [:ascii:] then you're saying "any one of :, a, s, c, or i".

That's probably not quite what you want either, though -- ) is an ascii character, after all, so (depending on your input) you run the risk of the closing paren getting swallowed in the [[:ascii:]]+ pattern. (e.g. if there was a subsequent closing paren on the same line.)

If you simply want to match everything until the first closing parenthesis, you would use a non-greedy operator, like so:

(\([[:ascii:]]+?\))

or if you know that it's safe to grab whatever is between the parens, you could more simply write:

(\(.+?\))

or perhaps you want (\([^']+?\)'?) ? (I've become a little unsure of the criteria after re-reading the question... if you want to replace only the exact two strings you've indicated, a non-regexp replace probably makes more sense...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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