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

How to set `org-agenda-files` depending current date in order to lessen number of files to load?

I use org-roam-dailies for my TODO lists for given day. And currently, I set my org-agenda-files to org-roam-dailies's directory as below: (setq org-agenda-files '("~/roamnotes/daily/")) ...
  • 357
0 votes
2 answers
49 views

Regex to find and replace a specific character inside of multiple quoted strings in a string

Given an example string of JSON (formatted here for reading, actual input may or may not be formatted): { "page":1, "per_page":6, "total":12, "...
  • 127
0 votes
1 answer
23 views

searching for <beginningOfLine><Comma>

how can I (interactive) search for <beginningOfLine>, I tried ^ which means beginning of line in perl Also \A which does signified the same in ruby. C-s ^, C-s \A, I also tried search-forward-...
1 vote
1 answer
44 views

What is the replace regexp string for applying 3 digit grouping to any number?

the title gives it all away: I want this 9874599842006432.08 To become this 9,874,599,842,006,432.08 with 1 single replace regexp operation and flexible, so that the same string also would work on a ...
2 votes
3 answers
52 views

How to programatically determine which alternative of a regular expression is responsible for a match?

Suppose I have a regular expression with many alternatives, such as "[a-z]+\\|[A-Z]+\\|[0-9]+" and it has just matched some text. I'd then like to know which of the given alternatives ...
  • 767
0 votes
1 answer
31 views

Why do Emacs Lisp regular expressions match the percentage and dollar sign as word characters?

I ran into this behavior by accident and it seems quite unusual to me. Why do Emacs Lisp regular expressions match the percentage and dollar sign as word characters? One theory I had was that this is ...
  • 139
2 votes
1 answer
79 views

Why "looking-back" does not match "[ \n]+"?

I want to do this replacement: \includegraphics{file } ==> \includegraphics{file} I wrote this code: (goto-char (point-min)) (while (re-search-forward "\\\\includegraphics{" nil ...
0 votes
0 answers
14 views

"-o" like options for `elgrep`?

Sometimes I just want the matched result by regexp instead of the whole line, this seems possible via the -o option in grep I discovered elgrep in emacs recently, which is fantastic! Any chance we can ...
  • 127
0 votes
0 answers
24 views

Change foreground colour or files showing error in rsync log file

I want to colour the file names that are logged with an error when using rsync. One such file will be as follows 2022/12/07 21:33:49 [3672] WARNING: b2-infocs/unix-like/2006-hagan-gcc.pdf failed ...
  • 179
0 votes
1 answer
46 views

Using general comment character used in programming languages

I am using highlight-regexp with a regexp pattern that includes the elisp comment characters ;;. How can I extend the pattern so that it adequately handle the general comment character for each ...
  • 179
0 votes
1 answer
58 views

Using a sub-expression for `highlight-regexp`

I have made a face to highlight elisp comments starting with ;; [ using hi-lock. My intention is to only colour the expression [text] using SUBEXP. (highlight-regexp "^;; \\[.+\\].+$" 'face-...
  • 179
0 votes
0 answers
15 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
30 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 ...
  • 767
0 votes
1 answer
32 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
75 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
51 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
31 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 ...
  • 207
0 votes
1 answer
20 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
13 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
42 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 ...
  • 455
0 votes
1 answer
34 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 ...
  • 455
0 votes
0 answers
18 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 &...
  • 455
0 votes
0 answers
48 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\\)" "" ...
  • 455
0 votes
1 answer
32 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
37 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
27 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
28 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 ...
  • 294
0 votes
1 answer
33 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
42 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
67 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
101 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
46 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
56 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?
  • 573
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 ...
  • 755
1 vote
1 answer
182 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 ...
  • 653
1 vote
1 answer
23 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? ...
  • 653
0 votes
1 answer
125 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
59 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.
  • 179
0 votes
1 answer
78 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) "...
  • 179
1 vote
1 answer
34 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
82 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 ...
  • 653
1 vote
1 answer
67 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
182 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
41 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
36 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
4 votes
1 answer
91 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 ...
  • 523
0 votes
1 answer
74 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
2 answers
70 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
2 3 4 5
10