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
0 answers
10 views

emacs multiple regex apropos

If I use apropos-command or apropos-documentation it prompts me for a word list or a regex. In the command line, apropos allows for multiple regexes where it only shows matches that match all the ...
1 vote
1 answer
10 views

Switch a TeX \macro and a script on a region of text

How can I search and replace in a region of a (TeX)buffer all occurences of \macro{foo}_{bar} to \macro{foo_{bar}}, foo and bar not being "constants" ?
  • 187
0 votes
1 answer
26 views

Weird behavior of `search-forward-regexp` influenced by buffer mode change

Action 1: evaluate the lisp expression: (search-forward-regexp "\\s'") in a buffer in lisp-interaction-mode containing the text: The pandemic market was cooling, but homes in north Seattle ...
  • 651
0 votes
1 answer
26 views

Highlight query-replace-regexp results while searching

I am terrible at remembering regular expression syntax. When replacing in by buffer with a regexp, I would like Emacs to highlight the possible matches while I am typing the regexp, so that I can see ...
0 votes
0 answers
71 views

Regexp for compilation-error-regexp-alist (react)

I try to add regexp for the compilation buffer (vite + react) for next output error: src/pages/MainPage/MainPage.tsx:18:18 - error TS2304: Cannot find name 'SocialMedia'. 18 <...
0 votes
1 answer
45 views

Does any package exist that can make interactive emacs-style regular expressions more readable by using font-locking?

Ideally the package would allow one to display emacs-style regular expressions, as they are entered interactively during a search and replace command, in a more human-readable form. Perhaps fewer ...
1 vote
1 answer
30 views

regexp-isearch with fixed prefix

I'd like to search a buffer for headlines only. A headline is anything starting with the "*" character. Ideally, I'd invoke an interactive function which would take user input at the ...
  • 205
0 votes
1 answer
19 views

regexp string matching a single word

I am looking to match the word as on its own and am using (s-replace-regexp "\\<as\\>" "s" word) Is this the way to it?
  • 51
0 votes
0 answers
12 views

Excluding punctuation in regexp when bounds-of-thing-at-point acts on word

I am doing (bounds-of-thing-at-point 'word) to capture words in a buffer. (let* ( (bounds (bounds-of-thing-at-point 'word)) (word (buffer-substring (car bounds) (cdr bounds))) I then ...
  • 61
0 votes
2 answers
41 views

Replacing words using multiple rules

This function is supposed to replace matches with a shortened version using multiple rules rather than just a single one. For the word counter, coun gets replaced by k, resulting in the shortened ...
  • 385
0 votes
1 answer
30 views

Using rx to insert word replacement

Been working on replacing regexps with the equivalent rx command, but the expression for rx is not producing the same result I get with the regexp. For the word counter, the regexp expression gives ...
  • 385
0 votes
0 answers
17 views

Scheme to write shortened words according to certain rules

I want to modify words according no certain rules. Here is a small example with three rules a) Insert k for words with initial cog, col, com, con, cor, coun, cum. (insert (replace-regexp-in-string &...
  • 385
0 votes
0 answers
32 views

Replacing single prefix from word

I want to omit the beginning of words starting with some (e.g. something changed to thing). This is the way I am doing it (insert (replace-regexp-in-string "\\<\\(some\\)" "" ...
  • 385
0 votes
1 answer
29 views

Using query-replace-regex to partially replace

I'm struggling with the basics of query-replace-regex after reading the manual. I'm trying to replace lots of citations formatted like this: #123213213, foo bar to #123213213\, foo bar the numbers ...
0 votes
0 answers
20 views

Extraction of reference and pdf from elfeed-entry

My elfeed is focused on finding papers and when I check out each entry, there is a PMID and DOI number at the end. PMID:39334129 | DOI:10.1207/s12102-021-03242-8 I wanted to call a function that ...
0 votes
0 answers
22 views

Extracting numbers from elfeed entry buffer

When I am in a particular elfeed entry buffer, I want to call a function that records the article in my .bib file by extracting the following PMID and DOI numbers from my elfeed-entry buffer: PMID:...
0 votes
0 answers
23 views

image-file-name-regexp: Wrong type argument: characterp

I wanted to mark certain filenames as images and added this to my config.el: (add-to-list 'image-file-name-regexps "/preview/") But when I run org-toggle-inline-images now, I get the ...
  • 274
0 votes
1 answer
31 views

Is it possible to mimic sed's "change line" feature?

I'd like to write an elisp function that allows me to replace any line in my buffer matching a regex pattern <PATTERN> with text <TEXT>. In other words, if line N matches <PATTERN>, ...
0 votes
1 answer
38 views

Is it possible to get the line number of the nearest regex match above the current cursor position?

I'd like to write an elisp function that tells me the line number of the closest regex match above my current cursor position. For example, if my cursor is on line 9 of the following file and my regex ...
0 votes
2 answers
66 views

Can't find anything about spaces in the official Emacs docs [duplicate]

I want to match every string that cointains a year and a month name e.g. like that: 2022 Jul or 2022 Jul (and more spaces than 2) or even 2022Jul. The regex I have so far is: "\\([0-9]\\{4\\}\\)&...
  • 35
2 votes
1 answer
64 views

Regular expression too big

Working to create my own major mode for sqf language (arma3 scripting) I get this error: Error during redisplay: (jit-lock-function 1) signaled (invalid-regexp "Regular expression too big") ...
  • 121
0 votes
2 answers
38 views

re-search-forward search for double and reverse quotation mark character

Good afternoon. Difficulties with creating a regular expression for this function. Interested in finding a double quotation mark or back quotation mark. Attempts at use were unsuccessful: (re-search-...
  • 59
0 votes
1 answer
51 views

Combine two commands

To create a list from sentences in org mode, I use following command string-insert-rectangle replace-regexp ^ with - How can I combine these two to form a single keyboard short-cut?
  • 563
0 votes
1 answer
24 views

regexp fails over expression involving {}

Over: \includepdf[pages={1-}]{example-image-a.pdf} I do / get M-x query-replace-regexp \\includepdf[pages={1-}]{.*} → \\includepdf[pages={1-}]{TEST} Replace 0 occurrences The problem comes from the ...
  • 651
1 vote
1 answer
134 views

Does Emacs have some kind of interactive regular expression editor?

I mean something like https://rubular.com/ where I can enter text and experiment with regular expressions to match that text.
0 votes
4 answers
54 views

How to match only the one word tag without the multiple word tag in image-dired?

In image-dired I use M-x image-dired-mark-tagged-files to mark files containing a tag e.g. bar (one word tag). The problem is that foo bar (multiple word tag) is marked as well. What regex do I need ...
  • 639
1 vote
1 answer
22 views

What is the image-dired regexp for line-end?

In image-dired I use M-x image-dired-mark-tagged-files to mark files containing a tag using regexp. e.g. jan. The problem is that jane is marked as well. What regex do I need to mark jan but not jane? ...
  • 639
0 votes
1 answer
85 views

How to properly use a regex for font locking

I'm stuck with a specific problem, I'm writing a major-mode for a language that supports multiple assignment, meaning that: let s = 9 let x, y, z = 1, 2, 3 var k = 11 var a, c = 4, 5 Are all valid ...
0 votes
0 answers
52 views

Measuring cyclomatic complexity of nested s-exp

I would like to measure the Cyclomatic Complexity on a file or a region of elisp code. By counting the maximum number of nested s-exp.
  • 169
0 votes
1 answer
65 views

Using a regexp for counting matches

I have the following function that uses a regexp for counting matches, but I have difficulty coming up with regexp expressions to test it. (defun rk-regex-count (regex rgn-beg rgn-end) "...
  • 169
1 vote
1 answer
23 views

searching for explicit spaces, without reinterpretation

Often I'll search (an ordinary i-search) for a sequence of two spaces, or three, or four. But on one machine I'm using, emacs by default appears to be in some mode where searches for spaces are ...
0 votes
1 answer
74 views

How to re-search-forward OR

How can I match the values for the keys (org mode attributes) #+label OR #+name? Example: Using get-labels () I got fig:foo. Nice. How can I get fig:bar as well? #+label: fig:foo #+name: fig:bar ...
  • 639
1 vote
1 answer
55 views

adding highlight to parts of a regexp

I am pretty new to emacs so please excuse the rookie question. So I am editing a helm chart template, and have enabled yaml-mode since most of helm uses yaml. but I wanted to add some highlighting to ...
  • 125
2 votes
1 answer
160 views

How to match two consecutive identical words except for the case of the initial characters?

I'm looking for a solution to match two consecutive identical words except for the case of the initial characters with query-replace-regexp: The the the The I can't figure out how to match these ...
0 votes
1 answer
33 views

Compilation mode error output parse not matching

I've below code (add-to-list 'compilation-error-regexp-alist 'kbd) (add-to-list 'compilation-error-regexp-alist-alist '(kbd "^kmonad: Parse error at \\([0-9]+\\):\\([0-9]+\\):" ...
0 votes
1 answer
35 views

Find and recursively delete (with query) consecutive duplicate words not necessarily in the same line and/or same case

I would like to scan through a (latex) document and recursively delete -- WITH QUERY -- all consecutive, repeated words that need not be on the same line and/or the same case. Here is a simple ...
  • 101
0 votes
0 answers
22 views

Why I need not single but double backslashes in regexps in auto-mode-alist? [duplicate]

Regexp syntax described in manual is \( for opening group of alternatives for example. So why I need \\( in auto-mode-alist? I love emacs and using it for years, but I never had a clear understanding ...
  • 101
0 votes
0 answers
42 views

Regexp syntax for helm-ag -G

I just noticed that ag -GFilenamePattern\.\*ext ContentPattern works from command line, but in helm-ag calling it with -GFilenamePattern\.\*ext ContentPattern does not (while -GFilenamePattern ...
  • 997
4 votes
1 answer
79 views

Why is the space character not in the space category (for regexp search)?

I'm trying to get better at using Emacs regular expressions. Reading the documentation I see: ‘\cC’ matches any character that belongs to the category C. For example, ‘\cc’ matches Chinese ...
  • 449
0 votes
1 answer
58 views

Use regex as key/car in alist

I'd like to set up an alist (similar to auto-mode-alist), which is made up from regular expressions as key (AKA car) of the list. Next I'd like to be able, to match, say the major mode, against the ...
  • 363
0 votes
0 answers
16 views

Collect all hashtags from all files within a projectile project

I have a projectile project full of markdown files with hashtags (#sample). I would like to read all the files within the project, collect all hashtags by regex, and use them with company for ...
0 votes
0 answers
20 views

Can't find text end by "Logger" in many files

Linux Mint 20.2 Emacs 27.2 In current folder and many subfolders I has many files with tne next content: private static Logger logger = Logger .getLogger(JdbcDefaultAccountStatusDao.class); Here ...
  • 3,587
0 votes
2 answers
53 views

Is this syntax parse possible with Emacs' regex expressions?

I'm trying to write a small new mode for some input files to a specific computational physics program. I'm doing it the define-derived-mode way, and was specifying the syntax highlighting by setting ...
  • 113
1 vote
0 answers
23 views

Can I limit refile targets with helm using a regular expression?

I would like to be able to use regular expressions in helm when selecting a refile target following an org-refile call. For example, if my list of targets includes 1. H1/ 1. H1/P1/ 1. H1/P1/C1/ 1. H1/...
2 votes
2 answers
60 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?

I should mention that I want to do this in emacs with its version of regex. Here's an example. I would like to change - \item - Property Agreement - Your agreement changing Joint ...
0 votes
1 answer
60 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 ...
  • 303
0 votes
1 answer
69 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,143
1 vote
1 answer
117 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? ...
  • 661
1 vote
1 answer
20 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 ...
  • 3,587
0 votes
2 answers
42 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-...
  • 670

1
2 3 4 5
10