1

I am trying to learn how to implement regular expressions in emacs. I have a string that looks like this:

Fname0 Mname0 Surname0Fname1 Surname1Fname2 

I would like to search for any capital letter and move the cursor to it. How do I go about doing that? I would later like to insert space and a comma in that spot.

1
  • highly recommend to install and use visual-regexp to build and replace regex visually, see the nice gif in the link.
    – fast tooth
    Commented Jun 2, 2021 at 0:49

1 Answer 1

1

You can do an interactive regexp search via the command isearch-forward-regexp, bound to M-C-s by default.

You can search for any upper-case letter via [A-Z], or [[:upper:]]. This will take you to the first capital after point. Pressing C-s will move to the next, which you can repeat.

To do this from elisp code, you can use the function search-forward-regexp.

Your question is very general, so it's hard to tell how familiar you are with Emacs and elisp code in general. If you're new to elisp, the tutorial might be useful. If you have some experience and just need to get oriented to Emacs/elisp, then the manual chapter on Searching and Replacing might be what you're after.

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.