0

I'm using evil mode on Emacs2 27.1 on OSX. My goal is to search and replace some text containing unicode strings using either of emacs' replace-regex or vim's search/replace functionality.

To begin with, let me showcase the example in vim without the use of unicode characters:

My text file has plenty of markers (let's say the unicode char i.e U2404) and I need to wrap the marker along with its preceding word into \mbox{}

E.g input text

This is a string।
This is another (string) ।
One more example string here    ।

This regex does the job for me in vim: %s/\((\?\w*)\?\)\s*।/\\mbox{\1 ।}/g

Output

This is a \mbox{string ।}
This is another \mbox{(string) ।}
One more example string \mbox{here ।}

Now, onto solving the real problem with unicode chars. Sample text:

This is a नमस्ते।
This is another (नमस्ते) ।
One more example string नमस्ते    ।

The above vim regex does not work because \w does not match unicode chars. However, I can use \S, which denotes any non-space character, in the regex to apply the search/replace with pattern %s/\((\?\S*)\?\)\s*।/\\mbox{\1 ।}/gc

This regex does not work in emacs' evilmode. Is there such a thing as \S in emacs' regex repertoire? I glanced through emacs' regex syntax and couldn't find anything.

What's the regex to use to obtain the same results as with the vim command %s/\((\?\S*)\?\)\s*।/\\mbox{\1 ।}/gc?

1 Answer 1

3

I don't use evil mode, so I've no idea if its regexes are different from ordinary Emacs regexes or not.

But if you use M-x re-builder, you'll see that "\\((?\\w*)?\\) *।" is a perfectly fine regex that matches all of your examples, with the group matching exactly what you want.

1
  • Works great. Thanks!
    – linuxfan
    Mar 12, 2021 at 0:24

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.