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
3
votes
3answers
870 views

elisp - regex to replace substring with multiple conditions

I want to replace below example line1 ![img](170319_first.png "test") line2 ![img](170319_second.png) line3 ![img](/assets/170319_second.png) to: line1 ![img](/assets/170319_first.png "test") ...
2
votes
1answer
295 views

A compilation-mode conundrum - matching and highlighting

Whilst playing around with compilation-mode for running tests and using HIGHLIGHT faces for failed expectations I've encountered a bit of a conundrum. Question: why does my compilation-errors-regexp-...
2
votes
1answer
124 views

loop (iterate) flush-lines on a list of regex for large files

I have a file (a log) with unique identifiers. I know I can exclude a single unique identifier in emacs using M-x flush-lines. I sometimes need to exclude more than one unique identifier, and for up ...
2
votes
1answer
493 views

help with regexp for compilation-mode (IAR EWARM )

I was wondering if anyone could help me figure out why the compilation-error-regexp for IAR ( compilation-error-regexp-alist-alist, in compile.el ) does not work? The regexp is: (iar "^\"\\(.*\\)\",...
6
votes
3answers
942 views

How to grep marked files in the dired mode of emacs?

I hope it's a simple problem.. I'd like to search for the regexp 'thisWord' only in the marked files of a dired buffer. Usually I used in the dired buffer: M-x grep and then in the mini-buffer grep ...
2
votes
1answer
145 views

Building a list of strings with a regexp while loop

I'd like to perform a regexp search, capture part of a matched string, and save that part to a list. (Eventually the plan is to save this list to a file in a particular format, but for now a simple ...
5
votes
1answer
49 views

Matching categories '\cX' and digit

The regex info material suggests that \\c6 should match digit characters. In UTF-8 encoded buffers it doesn't; some of the other category letters work as expected (l, |, a). Shouldn't \\c6* match ...
3
votes
1answer
33 views

how can i do for replace a part of a regexp

For example i have this text: select * from T1 ; select * from T2 ; select * from T3 ; My objetive is replace the text by this other: select * from T1_H ; select * from T2_H ; select * from ...
3
votes
2answers
208 views

How can I select only the content of a @media in CSS with regexp in Emacs?

I am trying to select the content of @media in CSS with regexp in Emacs (elisp) to make a slight change in the color of the background or font, so I can easily see that I am editing inside of them. I ...
0
votes
1answer
86 views

Why is “*\\Completions\\*” formatting used when specifying buffer names for display-buffer-alist?

From GNU Emacs Manual: 20.6.2: If you prefer Emacs to display a temporary buffer in a different fashion, we recommend to customize the variable display-buffer-alist (see Choosing a Window for ...
8
votes
1answer
879 views

What does a backslash followed by a single quote mean in a regular expression?

Looking at this stackoverflow answer on an old way for specifying the org-file-apps list, I can see that there is a backslash followed by a single-quote character after each file type extension, e.g. ....
0
votes
2answers
93 views

How to write an e-lisp function to extract a sub-string between two given characters (not their positions) in a given string?

I am writing an e-lisp function in my .emacs file to help process Bibtex entries I copy from Google-Scholar. Let's consider this example: @article{jacobsen2011full, title={A full hydro-and ...
5
votes
1answer
285 views

Equivalents to vim \zs and \ze?

In vim, all instances of an apple tree can be replaced by an orange tree with :%s/an \zsapple\ze tree/orange/g. \zs and \ze mark the start and end of the passage to be operated on. Is there something ...
2
votes
1answer
61 views

Better way to find regexp in emacs buffer

I'm trying to make a function to read a whole buffer and find lines that match with regexp, I think to read the whole buffer and save to list of strings but I read that it's very inefficient. Whats ...
2
votes
1answer
1k views

How do I match a closing bracket in Emacs lisp

I would think this was really simple. I am trying to match closing delimiters in Emacs Lisp regex. I can match {}()[ no problem, but I cannot match ]. I have been using re-builder and have tried "[\\}\...
8
votes
1answer
352 views

Most performant matching of “any char”

On https://www.emacswiki.org/emacs/MultilineRegexp one finds the hint to use [\0-\377[:nonascii:]]*\n instead of the standard .*\n to match any character up to a newline to avoid stack ...
2
votes
2answers
228 views

query-replace-regexp on specific lines

how does one do a query-replace-regexp to add a prefix string but not on EVERY line but rather just lines with text (or start with specific text?) i know how to add a prefix with query-replace-regexp ...
0
votes
1answer
457 views

How to match the URL component from a markdown link?

I've been trying to hide the URL component of the markdown links in my buffer. I could select the markdown links using "\\(\\[.+\\]\\)\\((.+)\\)" However, I just want to capture the second half (...
1
vote
2answers
220 views

Preventing font-lock string match from going past end of line

I have a custom mode to highlight my log files. In it, I attempt to highlight strings that are surrounded by double quotes("[^"]*"). In the files, there are sometimes lines with an odd number of ...
0
votes
0answers
168 views

Match regexp group

I am trying to modify org-wikinodes.el to match any org-mode headline (not just camelCase text. So I have replaced the default regular expression with: *\\s-\\(.+\\) This works. But in order to link ...
0
votes
1answer
149 views

Custom search function for dictionary lookup

I have a plain text dictionary in which each headword is matched by ^# \(† \)?headword, How can I make a custom search function that relieves me of typing the whole regex every time I want to look ...
2
votes
1answer
73 views

Constructing an advice around org-html--wrap-image

This is a follow-up question from a previous thread The function org-html--wrap-image adds a <p> tag around its contents, as you can see here: ELISP> (org-html--wrap-image "bla" t) "\n<...
2
votes
2answers
438 views

How can I get regexp-opt (or similar) not apply on the word with added underscore?

See excerpt below for code used in emacs Cadence SKILL mode: (cons (concat "\\<" (regexp-opt '("nil" "t") t) "\\>") 'font-lock-constant-face) it does a brilliant job at highlighting nil and ...
10
votes
1answer
3k views

Evil mode and regular expressions

In Vim, if I want search for all variable names LX where X is a number, I can simply type /L\d. However, this doesn't seem to work with evil. Is there another syntax for regular expressions in Evil ...
2
votes
1answer
405 views

Difficulty with query-replace-regexp

I'm having trouble getting query-regex-replace to do what I want. I've read the docs several times and still can't figure it out. Here are a few examples of things I can't figure out how to do with ...
4
votes
2answers
754 views

How can I add a compilation error regex for node js?

I can't seem to get emacs to recognize node stacktraces. As you can see, I've added what I think is a valid regular expression to compilation-error-regex-alist and compilation-error-regex-alist-alist, ...
0
votes
1answer
55 views

replace all '*' with spaces EXCLUDING org headers?

I converted a file to org-mode, but have a lot of extra asterisks. I want to replace each * with a space, but I want to exclude the * in a header line. How do I do this?
1
vote
1answer
494 views

Syntax highlighting: highlight text followed by a pattern, but not the pattern itself

I'm writing a major mode to handle syntax highlighting for a language that allows namespaces just like in C++ e.g. somewhere::out_there. I'd like to highlight the text somewhere, but leave the ...
4
votes
1answer
159 views

replace-regexp-in-string stops replacement with “^.”?

I've encountered a wierd situation when trying to match the first character of a string using a regex with alternatives. It seems that replacement stops when matching a single character using a ...
1
vote
0answers
75 views

Good way to match symmetric delimiters

I am trying to match $$ resp $ pairs to switch into latex-mode via polymode in a markdown file. $$ is the delimiter for displayed math in this case and $ for inline math. I know that this is not a ...
1
vote
1answer
140 views

Sort Dewey Decimal list?

If I have a list of books' call numbers in Dewey Decimal in a buffer, is this something I could sort with Emacs regex -- or is this an elisp task? For example, 261.1 C87 comes before 261.104 Z99 ...
3
votes
1answer
2k views

How do I lowercase (downcase) a group with replace-regexp?

I have some text that looks like this: "CFName" "CLName" "CDOB" "CGender" I would like to get output where are of the text inside the double quotes is ...
4
votes
1answer
931 views

regexp to find two consecutive and identical words not necessarily in the same line

According to https://www.emacswiki.org/emacs/RegularExpression#regexp \(\w+\) +\1\> finds two consecutive identical words. It works if the words are in the same line separated by an ...
1
vote
1answer
230 views

replace-regexp-in-string not replacing the entire match

So, I have a function that sends a URL to bit.ly for shortening and returns the short URL, and a (replace-regexp-in-string), which is supposed to grab the URL out of a string to passes it to that ...
2
votes
1answer
156 views

align (indent) in bibtex file

I have a bibtex file, and would like to have indentation as follows. @book{moon70:trees, AUTHOR = {John W. Moon}, TITLE = {Counting labelled trees}, YEAR = 1970, ...
0
votes
1answer
249 views

Left-align org-mode like FoldingText… Regexp?

I posted this question on stackoverflow earlier, but perhaps this is a better place for it? I am looking for a way to left-align text in Org-mode so that the paragraphs line up like in FoldingText. ...
0
votes
1answer
1k views

How to match this string with elisp regexp?

I'm writing an extension to open a custom link type in Org-mode with Kiwix URL. (Kiwix is an offline Wikipedia program). Here is my kiwix.el source code. I created a wiki: link type for Org-mode. ...
2
votes
1answer
133 views

Problem with replace-regexp - Invalid use of \ in replacement

I want to add extra expressions to some JS code, but taking care of the correct element ID (in the example below, the ID is scatter). document.getElementById("scatter").height="400"; --> document....
1
vote
1answer
58 views

Using reference in replace-regexp

What should I type in replace-regexp command to change the first list below into the second? I'd like to repeat each number at the beginning of line. To achieve that, I assume that I'll have to refer ...
0
votes
1answer
92 views

a function to clear out particular words/characters via regex

I have a specific request to all you regex wizards :) I want to create a simple function that deletes or cleans out several parts of a text file based on predefined keywords (such as single capital ...
0
votes
2answers
789 views

elisp trying to double backslashes in windows pathname - concat strips a slash escape

I'm trying to insert a string pathname into a buffer on a Windows machine. The variable holding the string has the right number of backslashes (two) in the directory pathname. I know this because when ...
3
votes
2answers
596 views

How do I use not in rx-to-string?

I just started working with rx and was able to achieve the opposite of the regex I wanted: (rx-to-string `(: (or (: line-start (not ,comment-start)) (: line-start (zero-or-more whitespace) line-...
3
votes
1answer
775 views

Regular expression matching group replacement not working

I want to convert .waitForVisible('.someselector') .click(); Into: .waitAndClick('.someselector'); Automatically in a lot of files. So I wrote: (defun hhaamm-replace-regexp-in-buffer (from to) (...
1
vote
1answer
1k views

Programmatically replace all instances of regex with capture groups and sub-matches in buffer

It is clear to me how to programmatically replace all instances of regex in a buffer with some text, something like (pardon my naive code): (defun my/regex-global-replace (regex subst-text) "...
2
votes
1answer
79 views

Match regexp groups or entire text

According to match-string help: Value is nil if NUMth pair didn't match In fact: (string-match "\\(hullo\\)" "hello") (match-string 1 "hello") gives nil Also, a NUM Zero means the entire ...
0
votes
1answer
54 views

Regex replacement of outer symbols

I have a lot of occurances of something =like_this= and I need to replace the both equals signs with this character: ` After looking at this question I thought the following would do it: M-x query-...
1
vote
2answers
72 views

Files for which to activate generic mode

I've created a generic mode for emacs, but I have trouble matching the file names I want the generic mode to be on, right now I'm using proguard-* but I would like to match only file names with ...
5
votes
1answer
275 views

How to use the regexp for digits with an interactive search?

For example, I have the following content in the buffer: 123 1234 12345 123456 1234567 To match the 4 numbers, I need the regular expression of \d{4}. I would like to do the same in Emacs, when I ...
9
votes
1answer
2k views

How to match symbol in regexp?

I'm trying to construct a regular expression that would match symbols, that is, things like function names and the like, according to current major mode settings (it's called syntax table if I ...
0
votes
2answers
50 views

Query replace and commenting out

I want to comment out all environments say myenv in a tex-file. I can find them with the regexp: \\begin{myenv}\(.\|\n\).*?\\end{myenv} (instead of \n I had do type C-q C-j). But what would be the ...

1
4
5
6 7 8