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
15 views

i have a regex that i want to apply only to the lines immediately following a \item line in a latex list. how do i do it?

Here's an example. I would like to change - \item - Property Agreement - Your agreement changing Joint Tenancy - property into Community property. to - \item - ...
0
votes
1answer
31 views

How to replace (blah) with {blah} for a specific string

In a latex document, I wish to replace \cost(blah) with \cost{blah} in the entire document, where blah is an arbitrary string. That is, I only want to change the round brackets to curly brackets for ...
0
votes
1answer
21 views

Escape all square brackets with replace-regexp-in-string

So I was writing a function that would convert one type of a link (e.g. Org-mode link) to another type (e.g. Markdown), and then I realized that Org-mode doesn't require you to escape square brackets, ...
1
vote
1answer
32 views

What is the meaning of the `\(?1::\)` Emacs string syntax regexp?

The bat-mode.el defines the following regexp used by re-search-forward: "^[ \t]*\\(?:\\(@?r\\)em\\_>\\|\\(?1::\\):\\).*" What is the meaning of the 1 in \\(?1::\\) inside the regexp? ...
1
vote
1answer
19 views

flush-lines: only upper case not working

Here's some text: test HELLO 999 help HOW ARE YOU buy aaa H d I need to remove all lines without uppercase. The result must be HELLO HOW ARE YOU H I tried M-x flush-lines [a-z] RET but the output ...
0
votes
2answers
22 views

Is there a way to delete the content under selected headers, but not the headers (and subheaders) themselves?

Is there a way to delete the content under selected headers, but not the headers (and subheaders) themselves? I.e., ** TOC *** PART 1: VECTORS AND GRAPHICS [[https://livebook.manning.com/book/math-...
1
vote
1answer
54 views

How to perform a multi-file regex-search with a regexp that encompass several lines?

Scenario: I want to detect all defcustom sexp that have a :set or :initialize keyword in all Emacs Lisp files inside a directory tree. Searching for newline can be problematic depending of the regexp ...
1
vote
1answer
68 views

How to I replace several texts like (1), (2), (3) etc. with fixed text (1), fixed text (2), fixed text (3) in one go?

My text contains several occurrences like "(1)", "(2)", "(3)". I want to replace these with the general format like "fixed text (1)", "fixed text (2)",...
0
votes
1answer
16 views

evil: Make `%s/x/y/gc` use case insensitive matching but do case sensitive replaces

How do I make %s/x/y/gc use case insensitive matching but do case sensitive replaces? In emacs terms, I want case-fold-search but not case-replace.
0
votes
1answer
31 views

Regexp replacement features

In the replacement part of :s in evil I can add commands like \l to lowercase the next char and \L to lowercase everything that follows, but I am unable to find documentation for that anywhere. I ...
2
votes
1answer
42 views

How to match the car of alist elements with a regexp?

I've spent a good amount of hours trying to solve this one but without success. I have an alist with strings (setq trees '(("pine" . "cones") ("oak" . "acorns") ...
0
votes
1answer
31 views

Replace regex in string elisp for emphasis like strings

I'm fairly new to Emacs and Elisp, and am tinkering around to customize to my liking. I'd like to be able to highlight some text in Emacs and also have it displayed when exporting to html, just like ...
0
votes
0answers
47 views

Highlighting all matched groups in font-lock-add-keywords rule

I'm trying to highlight variable-type in custom let-like form that looks like: (mylet ((<variable-type> <variable-name> <variable-value>) (...)) <some-forms>) To do ...
1
vote
2answers
80 views

Count number of lines between two consecutive matches

I have files such as these: 0000 0030 + Something + Another thing + One more thing 0200 + Something else + And one more thing 0230 In the above, the numbers represent time in HHMM format. I want to ...
0
votes
1answer
27 views

How to match a single ')' with replace-regex?

I want to replace a list in the form of 1) 2) 3) 4) with * * * I've tried using the regex [0-9]*\), but it gives Invalid regexp: "Unmatched ) or \\)" and [0-9]*\\) replaces 0 matches. in ...
0
votes
0answers
21 views

Defining a poly-mode for python docstrings

I was trying to define a polymode so python docstrings have markdown-mode in them. My code for now is: (use-package polymode :ensure t :config (define-hostmode poly-python-hostmode :...
0
votes
0answers
24 views

Command to fix internal org broken links in HTML export

I'm trying to export a bunch of org entries with numerous internal links to an external website. These links get broken during the export, but I can mostly recreate the correct URLs with some simple ...
0
votes
1answer
26 views

How can I fix my re-replace-region function in which match data gets clobbered?

I have an ancient function I've been using for decades which performs a regexp replacement in a region: (defun re-replace-region (begin end old new) "Replace occurrences of REGEXP with TO-STRING ...
0
votes
1answer
42 views

Do something for all regular expression matches

I have a named-and-saved keyboard macro that I want to apply to all regular expression matches. How to do that? (Related: I found this stackoverflow post: Running a macro till the end of text file in ...
1
vote
1answer
33 views

Search for a capital letter in a string and move the cursor to it

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 ...
1
vote
2answers
90 views

Using a variable as the REGEXP in `query-replace-regexp`

I know, Emacs allows calling ELisp while replacing a text with a regex, aka C-M-%, which is bound to query-replace-regexp. I'm trying to make use of that to store an unwieldy regexp as a variable, so ...
1
vote
0answers
13 views

Variant of read-regexp that shows matching string candidates upon TAB

I'm looking for an extension of read-regexp, that given an additional parameter of completion candidates, shows the matching subset of these candidates in the minibuffer, when tab is pressed. Similar ...
1
vote
1answer
190 views

How to find a newline with a regular expression in query-replace-regexp?

I am trying to use find-name-dired and query-replace-regexp to find and replace some blocks of text across multiple HTML files. (Just what is explained here in the Emacs Manual.) query-replace-regexp ...
1
vote
1answer
39 views

How reliable is it to OR multiple user defined regular expressions?

Given multiple regular expressions, how reliable is it to group these into a single regex, without knowing their contents ahead of time. e.g. (re-search-forward (concat "\\(" "...
3
votes
2answers
300 views

How to check a regular expression is valid without using it for a search?

I would like to write a package that uses user defined regular expressions. Is there a way to validate a regular expression is valid without having to perform a search, showing a helpful message when ...
0
votes
1answer
72 views

Regex to handle unicode strings in evil mode

I'm using evil mode on Emacs2 27.1 on OSX. My goal is to search and replace some text containing unicode strings using either of emacs' replace-regex or vim's search/replace functionality. To begin ...
2
votes
1answer
38 views

Regex to match one tag and not the other in image-dired

In image-dired I use M-x image-dired-mark-tagged-files to mark files containing a tag using regexp. e.g. oil. What regex do I need to mark oil but not wip (work in progress). Input: /foo/IMG_2022.JPG;...
1
vote
2answers
33 views

String-match: symbols variable void

I am trying to write a small function where I extract two sub-strings from a cite-key, e.g. cite:rammstein2017paris. (defun citekey-get-author-and-year () "Get the _author_ and _YEAR_ ...
0
votes
0answers
5 views

Change er/mark-method-call() - based on regex - to include square and curly braces

This is a function definition from expand-region.el, which does not accept new Issues. It looks at (), but not at [] or {}. How to change it to include other pairs too? (defun er/mark-method-call () ...
2
votes
1answer
55 views

How to replace the first element of the `kill-ring` by a modification of it?

I am trying to modify the string that is to yanked My goal is to modify certains paths before yanking, in order to transform them in relative to path actual buffer file. Following this post, I tried ...
0
votes
0answers
125 views

How do I split a side window?

I am using the org-roam package, which, while great, uses up the entire side window of my main emacs frame. I would like to use some of that side window to display something else, ideally an eaf ...
0
votes
1answer
44 views

Help with regex in re-builder : lines without "|" nor ";" at the beginning

I am starting regex with Emacs and cannot get the right regex. I would like to match the line 1 and 4 in the image below, where variable-pitch is "active" and do not match 2 and 3 where is &...
0
votes
0answers
10 views

remove erroneous commands from ESS transcript

I'd like to better use my ESS transcript file while working on R. I know how to clean the .Rout file only keeping the command lines. But what could be great is to remove all the command lines that ...
0
votes
1answer
163 views

replace-regexp-in-string: How to prepend a string to the entire string matched?

I am adding divider lines to certain sections of the reports generated by the binary ledger [ https://www.ledger-cli.org/ ] through the function ledger-do-report in the ledger-mode Lisp library [ ...
0
votes
1answer
96 views

How can we get input using emacs?

In order to compile my lua code i use this config (defun lua-main-compile () "use lua to compile my lua code" (interactive) (compile "lua main.lua")) In my lua code ...
1
vote
1answer
46 views

How can I get the search string from incremental regexp search to use with replace regexp

If I want to do a replace-regexp I usually start with a isearch-forward-regexp so I can get immediate visual feedback on the search string. From there I'd like to grab the search string for using in ...
1
vote
1answer
67 views

Regular expressions tool example explanation

Reading the section regular expressions in EmacsWiki appears this: You can use a tool to construct regexps. For example, you can use ‘rx’ like this: (rx (or (and "\*" (*? anything) "*/&...
0
votes
1answer
122 views

Regex to replace subset of repeated pattern

ABC、DEF, GHI, JKL、MNO PQR、STU, VWX、YZ How do I replace all , s with 、 in the repeated pattern above? The repeated pattern can be mapped with the regex below: "^\\([A-Z]+、\\)\\(\\([A-Z]+\\), \\)+&...
0
votes
2answers
51 views

How can I paste a defvar into the minibuffer?

I've written a regular expression to transform Markdown links into Org Mode links and I've stored it into a variable. (defvar markdown-link-to-org-regexp "s/\[\(.+\)\](\(.+\))/[[\2][\1]]") ...
4
votes
1answer
756 views

Regex for the last line of a string

I'm trying to search for the last line in a string (lines separated by \n) using string match but I cannot make it work as intended. The code below evaluates to 0 while I would have expected 4. I ...
1
vote
2answers
295 views

Remove everything except match of regexp?

I have a file with a structure like: some text and numbers and a final number: 1.213,31 some other number 1231 and text again some text and a final number: 53,00 something else again a final number: ...
1
vote
1answer
22 views

Interactively pass argument and use regex in find replace

I have written the following code (defun krmet-replace() (interactive) (save-excursion (save-restriction ;; Narrow to the region (narrow-to-...
1
vote
1answer
137 views

org-mode: specifying a hyperlink target as regex and jumping directly to match?

The documentation of a Fortran code, being done in org-mode, is intended to be done in such a way that changing the Fortran source code to be documented should be kept at a minimum. There is the ...
1
vote
1answer
163 views

Emacs outline-mode custom heading and space between headers

I'm trying to define a structure for outline-minor-mode so I can organize my init.el conf without relying in org. So far I could not get to work with two levels of heading, I would like to have ;;; ...
1
vote
1answer
29 views

Syntax highlighting of keywords only if following builtin

I'm writing a syntax highlighting mode and am trying to highlight certain arguments, only if they are following a specific word. I've written a MWE to show my problem: (defvar mwe-builtin-list '("...
1
vote
1answer
37 views

Decode double-back-slashes-prefixed octal codes in 'utf-8

I have a string "\\303\\273" that I want to decode into û. It's known that (decode-coding-string "\303\273" 'utf-8) evals to û. However, I'm not able to translate "\\303\\273&...
1
vote
1answer
33 views

flush-lines fails in script but works when called otherwise

I'm very new to programming in Elisp so maybe the mistake is there but I'm completely stuck right now. I wanted to make a small, simple Elisp function to remove the AUTOs from my Verilog files so I ...
1
vote
2answers
143 views

Remove multiple blank lines in a buffer, leave one

I'd like to take a buffer which looks like this: one two three four five And turn it into this one two three four five I've tried using delete-blank-line, however, it will only effect the area ...
0
votes
1answer
34 views

.+$ fails to match remainder of line

This matches nothing: Query replace regexp (default \.org.+ → ): \.org.+$ → The same without '$' matches incompletely: I'd like to be able to match \.org and all that follows.
1
vote
2answers
202 views

Filter list by regexps

How can I get all elements of a list which don't match multiple patterns? The patterns are given as a list. For instance, I want all files without '("no" "nix") in them. (setq se-...

1
2 3 4 5
9