2

Here's an example of content in a file

This_is_line_1    :  1
This_is_another_line  :2
This_is_3rd_line    :3
Here_is_line_4 :4

So, how can using emacs to add char @ immediately to the end 1 string on each line, i.e.

This_is_line_1@   :  1
This_is_another_line@  :2
This_is_3rd_line@    :3
Here_is_line_4@ :4
Drew
  • 77,472
  • 10
  • 114
  • 243
vbrnrt
  • 23
  • 2

1 Answers1

2

Go to the beginning of the buffer an call query-replace-regexp. You can call query-replace-regexp by the menu item "Edit → Replace → Replace Regexp". Alternatively you can use the key-sequence M-C-% that is shown beside the menu item.

Use ^[^[:space:]]+ as regular expression (regexp) and \&@ as replacement string.

Notes:

  1. The first caret in the regexp matches the empty string at the beginnig of the line. It anchors the match at the beginning of the line.
  2. The outer braces [...] describe a character set. Each of the contained characters match.
  3. The caret in the character set negates the set. I.e., all characters not in the set do match.
  4. The [:space:] is the character class of characters with space syntax.
  5. The + matches one or more instances of the previous expression, i.e., of the character set.
  6. The regexp is greedy by default. That means as many as possible chars are matched.
  7. The \& in the replacement string references the full match.
Tobias
  • 33,167
  • 1
  • 37
  • 77