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
0
votes
1answer
120 views

use a function to get file in compilation-error-regexp-alist

I have used compilation-error-regexp-alist a lot so I am familiar with the syntax. However for this particular error I need to use a function to get the file because I need wildcards. Here is the ...
0
votes
2answers
97 views

Create strings of a wordlist using replace-regexp

I have a word list with a lot of words that I want to convert into a json file. To do this I need to make them strings and add a comma in the end of all words. I figured it would be nice to use ...
0
votes
1answer
97 views

Using a predefined Regex on a yank

can you please help me to write a small emacs function? This is the first lisp function I am writing and I think I am getting confused with point and mark placement. I want to write a function that ...
1
vote
0answers
128 views

Change regex-builder-mode hook to use <C-s>

I recently discovered emacs's "regex-builder" mode and am absolutely loving it. However, there doesn't seem to be an easy way to type in an expression in the "RE-Bulider" buffer and use that ...
0
votes
2answers
88 views

Removing and adding newlines around expressions

I am in the process of formatting a couple of hundred markdown files and am trying to automate that process. I am having two problems, but I guess I can ask two questions ;) Goal I am trying to ...
3
votes
1answer
548 views

Find and remove consecutive duplicated words while ignoring case

I am trying to find and remove duplicated words in a LaTeX file. Right now I am using query-replace-regexp with the regular expression \b\(\w+\)[ #]+\1 where # stands for line-break (C-q C-j). This ...
1
vote
2answers
620 views

How to extract some text from within HTML code?

I have this string in an elisp variable <br /><b>Country</b>: United States<br /><a href I want to extract out the United States in to a separate variable. How can I do ...
0
votes
1answer
106 views

Function that returns the name of a Greek vowel

I'm trying to write a function that will return the name of a Greek vowel: alpha or epsilon etc. I was hoping this could be done by extracting it from the second group in the following regexp (in a ...
0
votes
2answers
62 views

Modify regexp in function to match only capitalized words

I have the following function (defun fphp/find-unimported-classes () (interactive) (mapcar (lambda (classentry) (ov-clear (classentry-overlay classentry)) ) ...
0
votes
0answers
111 views

Interactively matching beginning of region

Short version: If i bound the scope of a search/replace to a region in the buffer (via the second/third optional argument of search-forward and its derivates), how can i match the beginning of that ...
1
vote
0answers
39 views

JavaScript regular expressions in re-builder

Is there any package that allows me to input regular expressions following the JavaScript syntax (or even Perl Compatible Reg. Exp.)? I want to have an interactive regular expression builder (like re-...
0
votes
1answer
2k views

Matching a literal asterisk (*) in a regexp

I am trying to write a regexp to mean: At least one of a few punctuation marks followed by any number of blank spaces followed by a literal star is to be replaced by all those punctuation marks ...
0
votes
1answer
53 views

How to bypass lines matching some regexp, when searching forward

I've written the following function to go from an error line to the next one: (defconst mylog-mode-error-regexp "\\(\\[ERROR\\]\\|rule did fail\\)" "Regexp to recognize errors in my log file.") (...
0
votes
1answer
330 views

How to use flush-lines in a script?

I want to use flush-lines in a selected region, but I have troubles. Here it is my code: (defun delete-empty-lines () "Delete empty lines in bibliography." (interactive) ;; set point-min (...
1
vote
1answer
285 views

Produce \' in a string replacement

As you know, functions such as replace-regexp-in-string and replace-match have an argument LITERAL, meaning ... If optional ... arg LITERAL is non-nil, insert NEWTEXT literally. Otherwise treat ‘\’ ...
4
votes
1answer
564 views

How can I use more than 9 regex capture groups in Emacs Lisp?

I have to do a regexp replacement with more than 9 capture groups. How can I do it? Here there is my code (with \\10 and \\12 that they do not work as I expected to): (perform-replace "\\\\href{...
0
votes
1answer
145 views

Org todo list: Filter regexp

When I press C-c a M and search for a certain tag, I get a todo list of all open tasks for this specific tag. Is it now possible to do a regular expression search similar to the sparse-tree regular ...
1
vote
1answer
339 views

Why do regexp that matches text in buffer does not (necessarily) match same text in string?

I have a regexp, org-parse-regexp which matches org items which I define to be a heading and a source block (actually, I include more stuff but I want to keep it simple). I've tested it using re-...
2
votes
1answer
273 views

Jump to and highlight characters matching regex

How can I jump to the next character matching a regex (see example below)? And if possible, enable highlighting of all the matching characters in the buffer when I jump for the first time. [^\x20-\...
5
votes
2answers
2k views

How to toggle regex for helm/ivy user input?

IIUC, all helm commands (including helm-swoop, swiper-helm) have regex enabled by default for user input. Can we toggle/disable it by some command/shortcut? Let me know if I missed something. Using ...
0
votes
1answer
71 views

case-fold-search apparently not taking effect in re-search-forward

I wrote the following command to do a regexp replacement in a region. (defun camel-case-to-underscore (a b &optional use-dash) (interactive "r") (save-excursion (let ((sep (if use-dash "-...
7
votes
1answer
5k views

how do I quickly remove lines from emacs buffer

In an emacs buffer when editing a file called "log/development.log" how do I quickly remove all lines containing the word "Render"
0
votes
3answers
502 views

Help with `replace-regexp-in-string`, to replace only first instance in every line

I have the following string: // const asdf = 'asdf' // // comment // const asdf2 = asdf And I want to run a regexp replace to make it look as follows: const asdf = 'asdf' // comment const asdf2 = ...
2
votes
1answer
30 views

turn coherent string into individual characters

I have a text with a number of coherent strings, e.g.: ax923fasd asidna1 xxa008 Is there a quick way to convert these so that there be a space between each of them, i.e.: a x 9 2 3 f a s d a s i d ...
1
vote
2answers
187 views

re-search-forward through visible text only

I have one big org file. Sometimes I only want to search for a regular expression through the visible text, not the text that is folded; otherwise my search will take much longer. How can I search ...
0
votes
2answers
122 views

What is the equivalent of “\n\t ” in string mode in re-builder?

This webpage recommends being in the string mode when using re-builder, the interactive regexp builder, where one does not have to use "\" to escape special characters. But how does one convert ...
0
votes
1answer
154 views

How to define abbrev boundaries and where to put them?

I'm new to Emacs and Common Lisp. I'm wanting to use abbrev-mode to replace standard Common Lisp function names with aliases that I have created. So for example, I would like to replace the following ...
2
votes
2answers
450 views

How can I use Regexp to rename files in Dired mode?

I've have some videos (.mp4) with subtitles files (.SRT) that I need to rename. These files have long names so I can only rename them manually. I've tried Python to rename them, but it fails. I've ...
2
votes
2answers
158 views

Syntax table to match arbitrary forms with regexp

I'm trying to write a small major-mode for editing pico-8 files in emacs and I had a quick question regarding best practices and matching a somewhat arbitrary form in the pico-8 cartridge files for ...
3
votes
2answers
2k views

Display another symbol than asterisks in org headings

I would like to change the way headings render while still using the * to type headings (so this question is distinct from Change the asterisk (heading identifier) to some other symbol in Org mode) I ...
1
vote
1answer
434 views

how remove all but the first n chars

How can I remove all but the first n characters of a every line in the file buffer? What I tried Mark region C-x r k #but this is cumbersome when the length of lines are very varied, and there are ...
1
vote
1answer
573 views

How can I match a tab not at the beginning of a line?

In Emacs, when using M-x replace-regexp, how can one specify matching a tab which is not at the beginning of a line? I know how to match a tab which is at the beginning of a line by using ^, but don't ...
13
votes
2answers
2k views

Incrementally replace a given string

Let us say I have a text like so below: AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) AC(nn) Now I want to replace the nn with numbers like so AC(0) AC(1) AC(2) AC(3) AC(4)...
1
vote
1answer
248 views

Emacs Compile Mode: Extra characters before filename result in bad match

In the compile buffer of Emacs 25.3.1, I am getting the following compilation error using Clang (the error message is given as it appears in the compile buffer line by line) : src/platform/linux/...
2
votes
1answer
68 views

Why does ^#.*#$ not capture recursively inserted files?

While considering some refactoring, I made changes throughout a project. Halfway through the changes, and before saving, I found it doesn't quite work. I exited emacs and restarted. (That's probably ...
1
vote
0answers
48 views

How to set ps-end-cut-regexp

I often use ps-print-buffer to print out files, but I don't want the first few lines of the buffer to be printed. Here's the beginning of the buffer: # -*- mode: org; -*- # Last updated: <2017/12/...
0
votes
0answers
144 views

Prettify string, find by regex

I want to replace the regular expression `.*` by bolding .* and not displaying the backticks. So I want `elem` to become elem I looked into these questions about how to prettify strings rather than ...
3
votes
1answer
392 views

Find/replace in differrent file extensions

Windows 10, Emacs 25.1, Dired+, xah-find I use package xah-find for find/replace text in many files. OK. It's work. If I want to find in all java files I use the next regexp: File path regex: \.java\...
3
votes
1answer
220 views

highlight different regexp groups with different colors

Is there a way, that each group in regexp can be highlighted with a different color. For example, if I am searching for \(text_part_1\)\|\(text_part_2\) Can the text_part_1 be highlighted in one ...
2
votes
1answer
76 views

ibuffer hide beginning of lines

When I press C-x C-b I get ibuffer (installed as part of prelude I think) I like to press backtick and get the Filename/Process displayed. Another SE answer helped me with that. (ibuffer hide columns)...
0
votes
1answer
88 views

Strange regex behavior

I want to skip blank region under cursor, so I created this regex: \s+\w translated to emacs regex [:space:]+[:graph:] but it doesnt match what I want. It matches some random space somewhere! Whats ...
1
vote
1answer
166 views

Executing multiple replacement regexps against a string

I wanted to write a function that "auto-corrects" a string, based on a list of regular expressions and their respective replacements. I've come up with this, and it works: (setq auto-corrections-...
0
votes
1answer
172 views

Using result of an Elisp function as input to replace-regexp in interactive mode

I am using replace-regexp interactively. Can I programmatically refer to a match or otherwise interpolate values in the replacement string? In Ruby, for example, it is easily done, by using the #{ <...
1
vote
1answer
235 views

Exact match for isearch

I am relatively new to emacs. I am looking for a way to do the "exact match" type of interactive search. For example, search string "abcDEF" in following text should only match with line1's text: ...
1
vote
1answer
170 views

elisp replace float number with half value

I need to replace below string: (24.0000,28.0000) .. controls (27.3100,28.0000) and (29.9800,25.3100) .. (29.9800,22.0000) to: (12,14) .. controls (13.655,14) and (14.99,12.655) .. (14.99,11) The ...
4
votes
5answers
335 views

find end of string constant

I'm using a simple (re-search-forward "\"") to find the end of string constants in my buffer. This is to copy the string in a def like (defconst name1 "some string"). The problem is that string ...
3
votes
2answers
218 views

Query-replace-regexp alternative capable of handling nested braces?

TL;DR Is there some method in Emacs to replace text with nested braces/parentheses? Example I had a situation where I had to replace \dchi{ARG1}{ARG2} by \chi^{ARG2}(ARG1) For simple cases, ...
9
votes
2answers
910 views

Search through the values of all variables in Emacs

I'd like to find which variables contain a certain value. Is there a way to do a regex search through the values of every variable in Emacs?
2
votes
2answers
350 views

Enable mode if file content contains a matching string

I would like to enable rjsx-mode whenever a file I open contains a specific string, or a regex like import.*react for example. Is there a way to do something like this in emacs?
0
votes
1answer
59 views

In emacs while using M-x replace-regex, the expression matches except when i put a ^ and $ at the beginning and end. This is confusing to me!

The search query is : ([\s]*print)[^(](.*) It matches, BUT when I put ^ and $ like this : ^([\s]*print)[^(](.*)$, it doesn't. Again both work in search-forward-regex but the 2nd one does not work in ...

1 2 3
4
5
8