Questions tagged [regular-expressions]

is for patterns specifying search or replace strings. Also known as `regex` or `regexp`, the patterns describe strings to match when searching or replacing. Emacs provides extensive support for `regex` patterns in many commands. Emacs also provides an interactive expression builder for such patterns.

Filter by
Sorted by
Tagged with
5
votes
1answer
1k views

How to save part of a regular expression during search and replace?

I think the best way to explain what I'm trying to do is using an example. Suppose one would want to replace all underlined words with italic ones in org-mode using a regular expression: _example_ --&...
6
votes
1answer
365 views

Using the count of coincidence from a regexp as replacement text?

I have an org-mode file with more than 12000 footnotes (maybe less), I was cleaning it and found that after the conversion some footnotes weren't converted to org-mode footnotes, so I had to manually ...
5
votes
2answers
254 views

Replace a two-line string not ending in digit with a one line string

I would like to replace a two-line string not ending in digit with a one line string. For example, replacing the following two-line string: Extensions of the Single—Sa1e Model 414 With a one line ...
4
votes
1answer
195 views

Regexp to parse Hy errors for Flycheck

I'm trying to write a Flycheck checker definition based on Hy, using the API here. As part of that, I have to define a pattern for error matching. Now, Hy gives quite a large error spew, for example: ...
6
votes
1answer
2k views

In regular expressions, what's the difference between [:blank:], [:space:], and \s-?

I've been playing around with rx lately, and I just noticed there are (at least) 3 different ways of indicating whitespaces in regular expressions. [:blank:] [:space:] \s- What are the differences ...
5
votes
1answer
1k views

Why are double quotes not escaped in the replace-regexp command?

I have text like this: myvariable = ABCD, EFGH, IJKL, ~subsection1 MNOP, QRST, UVWX, YZ Which I want to transform to: myvariable = "ABCD," "EFGH,\n" \ "IJKL,\n" \ "~subsection1\n" \ "MNOP,\n" \ "...
2
votes
3answers
177 views

Convert regexp list so that each member has word boundaries

I have several lists with regexp matching categories of file extensions: (let* ( (txt-regexp '("txt" "md" "log" "org" "conf" "rtf")) (el-regexp '("el" "lisp")) (tex-regexp '("tex")) (...
3
votes
1answer
167 views

Composing a regexp to highlight folder extensions differently

I am having difficulties composing a regexp that will highlight certain folder extensions -- including the preceding dot -- with colors that are different than the rest of the folder -- e.g., .app ...
32
votes
2answers
6k views

Understanding of emacs align-regexp

I've read the Emacs documentation for align-regexp but still have difficulty in understanding how it works. What I'm talking about is its prefixed form C-uM-xalign-regexp, not the simple form M-xalign-...
13
votes
3answers
3k views

Is there an equivalent to sed-style substitution commands from vim?

One of the things I miss from vim is being able to type in a substitution command that will work over multiple lines, for example: :/begin/,/end/s/foo/bar/g The above command substitutes "foo" for "...
14
votes
1answer
810 views

How do I create a dynamic regexp with rx?

I want to use rx to create regular expressions with runtime values. Currently, I'm doing this: (setq strings '("foo" "bar" "baz")) (eval `(rx symbol-start (or ,@strings) symbol-end)) However, I'd ...
6
votes
1answer
756 views

Regexp replacement: difference between \([[:digit:]]+\) and ([[:digit:]]+)

With M-x replace-regexp, I found that both \([[:digit:]]+\) and ([[:digit:]]+) will match (123), and not one without parentheses, But the first will replace 123 and the second (123). I wonder why the ...
12
votes
7answers
1k views

How can I practice searching and replacing with regular expressions interactively in Emacs?

Searching and replacing using regular expressions is clearly a powerful tool to the Emacs user who can routinely perform these actions. However, as an Emacs (and/or programming) beginner, regular ...
15
votes
2answers
693 views

How can I test and use a Perl regular expression interactively?

Say I have a buffer with text. I would like to test a regular expression (ideally Perl type) against my buffer and have Emacs highlight the matches on it. For example, the following regexp (taken ...
9
votes
1answer
823 views

Align vertical columns of numbers on the decimal point

I wrote this post in Emacs. In order to make the tables look nice, I decided to adjust the spacing so that decimals line up neatly. The original format from the database looked like this: emacs ...

1
4 5 6 7
8