As of May 31, 2023, we have updated our Code of Conduct.

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.

59 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
1 answer
1k views

Generate a date tree from timestamps in org-mode

Since I was interested in doing my early capture-templates, I was tempted to go with this template below: ("j" "Reference type: Journal" entry (file+headline "~/Dropbox/orgfiles/gtd/ref.org" "...
doctorate's user avatar
  • 1,759
4 votes
0 answers
153 views

LaTeX-aware sentence endings?

Q: how do I define sentence endings to be LaTeX macro-aware? I'd like backward-sentence and forward-sentence to be smarter about LaTeX macros -- particularly \footnote -- when working in LaTeX ...
Dan's user avatar
  • 32.3k
3 votes
0 answers
128 views

Is point in a regexp?

I am looking for something like thing-at-point for a regexp. For example, I want a function called regexp-at-point-p that will return the matched text if the text around the point matches the regexp ...
John Kitchin's user avatar
  • 11.5k
3 votes
2 answers
314 views

How to count regexp in a string and use that number in replacement?

In my LaTeX code I want to replace these strings: \left.\left.\left. \left.\left. \left. with: \left.\left.\left. \mycommand{3} \left.\left. \mycommand{2} \left. \mycommand{1} where the argument ...
Gabriele Nicolardi's user avatar
2 votes
2 answers
47 views

Colourize buffer names differently for the files located in different directories

I am working upon 2 projects that have similar structure. And sometimes occasionally modify a file in the wrong buffer. So I desided to set different colours for the files in the different projects: (...
user4035's user avatar
  • 1,019
2 votes
0 answers
87 views

org-table: hide grid lines

I like how org-mode allows me to quickly create and edit tables. However, I do not like the table's appearance and I would like to modify it. Customizing the face only lets me change foreground and ...
jollaWellbuur's user avatar
2 votes
1 answer
98 views

Switch from Dired to Wdired rename file and directory errors when using "-F" or "--classify" ls switch regex help

If you set -F or --classify in the dired-actual-switches then it places a / at the end of directory names and * at the end of executables. When you finish renaming the files, these characters are ...
J Spen's user avatar
  • 171
2 votes
0 answers
339 views

Automatic radio targets from org-mode headlines

Is there a way to have headlines in org-mode automatically behave as radio targets? Basically, I am looking for each line starting with * get turned into a radio target. For example: * My Headline ...
Adam's user avatar
  • 1,847
2 votes
0 answers
84 views

Upper/lower regexp char classes and current-case-table

I seem to have a problem with [:upper:] [:lower:] and Unicode characters. This test fails: (ert-deftest haskell-upper () (set-buffer (get-buffer-create "*haskell-mode-buffer*")) (insert "Ż") (...
Gracjan Polak's user avatar
1 vote
1 answer
71 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 ...
munHunger's user avatar
  • 125
1 vote
0 answers
29 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/...
user2567544's user avatar
1 vote
0 answers
23 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 ...
Nordlöw's user avatar
  • 467
1 vote
1 answer
283 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 ...
Harald's user avatar
  • 11
1 vote
0 answers
121 views

Ignoring specific files in recentf-mode by their exact filenames

I am having trouble to Ignoring specific files in recentf-mode. (add-to-list 'recentf-exclude "company-statistics-cache.el") On my end, I want to ignore them by their exact file names instead of ...
alper's user avatar
  • 1,154
1 vote
0 answers
98 views

Why correct regexp not work in query-replace-regexp?

I want to add 400 in every line where has text "finished". Here text and regexp: as you can see the regexp is correct "finished":\s-*[0-9]+ Nice. Now I use this regexp in query-replace-regexp ...
a_subscriber's user avatar
  • 3,830
1 vote
0 answers
85 views

Is there is an existing parser for `.gitignore` files?

Is there is an existing parser for .gitignore files? Maybe there is some Elisp package that includes something like this? Ideally, I would like to be able to read a .gitignore file in a given ...
krokodil's user avatar
  • 121
1 vote
0 answers
66 views

Simple regexp inside emacs keyboard macro

Newbie question: I'm trying to record a keyboard macro with a simple regexp inside (search-backward-regexp ^[0-9]). This works well when recording the macro, but as soon as I try to execute it, the ...
Joachim's user avatar
  • 11
1 vote
0 answers
70 views

How can I split LaTeX inline math from preceeding or following sticked words?

I have this LaTeX code: Lorem $math$ ipsum $math$dolor sit consecteruer adipscing elit, sed do eiusmod tempor incidunt ut labore et dolore magna aliqua. $math$Ut $math$ enim ad minim veniam$math$, ...
Onner Irotsab's user avatar
1 vote
0 answers
354 views

Regular expression to match a URL

I am trying to construct a regexp for URLs (for grabbing them out quickly out of a paragraph, region, etc.). I don't need it advanced, but I am having some troubles with it. Here is my attempt, which ...
user3496846's user avatar
1 vote
0 answers
154 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 ...
Ricardo Iglesias's user avatar
1 vote
0 answers
52 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-...
rph's user avatar
  • 315
1 vote
0 answers
49 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/...
GrB's user avatar
  • 207
1 vote
0 answers
317 views

Help Aligning a Pattern with `align-regexp`

How can I use M-x align-regexp to align by // All ; after // All , within [] after // For example: With text: Line 1 ; B // Comment 1 [11, 22] ; Comment 2 [3333, 4] Line 2 C // Comment 3 [3, 55] ...
George's user avatar
  • 869
1 vote
0 answers
69 views

using re-search-forward in yas-snippet

I'm trying to develop a new yas-snippet for expanding a common c++ log function I use a lot. The first parameter to the LOG function can be guessed by searching for existing LOG calls in the buffer. ...
Chris H's user avatar
  • 133
1 vote
0 answers
84 views

Can you use a regexp in an abbrev definition?

I want to replace words like 1st with 1^{st} and 102nd with 102^{nd} while typing in emacs. Basically I want to replace things that match this: "\([0-9]+\)\(st\|nd\|rd\|th\)" with this \1^{\2} as I ...
John Kitchin's user avatar
  • 11.5k
1 vote
0 answers
101 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 ...
student's user avatar
  • 997
1 vote
0 answers
271 views

org-mode smart-quotes (probably prb with the regexps)

I have a problem with org smart-quotes. There are two cases that don't seem to be covered by the standard regexps to identify quotes, namely in the case '" and the case "'. The double quote in both ...
mat's user avatar
  • 11
0 votes
0 answers
7 views

Sorting emails using the suffix first / "Invalid back reference"

I have a list of emails that I want to sort first by suffix, second by prefix: M-X sort-regexp-fields RET \(.*\)@\(.+\) RET \2\1 I get: Invalid regexp "Invalid back reference Could someone ...
Erwann's user avatar
  • 848
0 votes
1 answer
15 views

How to use regular expressions with helm-projectile-grep?

I would like to find all strings in files matching the pattern foo_*_bar. I know that one can use \s to match empty characters. What's the pattern for zero or more characters? Could not find it by ...
honey_badger's user avatar
0 votes
0 answers
14 views

Highlighting strings in Org and Markdown mode doesn't work with *bold* or /italic/

I want to highlight strings between double quotation marks in org-mode and markdown-mode, just so they're easier to see, as in LaTeX-mode. I have the following in my .emacs: ;; Highlight strings ...
Joel Adamson's user avatar
0 votes
0 answers
21 views

How to align source code section in both Org-src-edit-code, Org-mode, and exported PDF file?

How to configure emacs such that code (in this case :which-key) is aligned in both org-edit-src-code org-mode and exported PDF? I'm guessing this is somewhat related to tabs getting different amount ...
Garid's user avatar
  • 505
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 ...
davyjones's user avatar
  • 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 ...
Veak's user avatar
  • 199
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 ...
Progamer's user avatar
0 votes
0 answers
79 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 <...
Artawower LH's user avatar
0 votes
0 answers
15 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 ...
Gibran's user avatar
  • 61
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 &...
Ephram's user avatar
  • 455
0 votes
0 answers
56 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\\)" "" ...
Ephram's user avatar
  • 455
0 votes
0 answers
43 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 ...
user38601's user avatar
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:...
user38601's user avatar
0 votes
0 answers
31 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 ...
xeruf's user avatar
  • 294
0 votes
1 answer
132 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 ...
Nathan Furnal's user avatar
0 votes
0 answers
62 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.
Veak's user avatar
  • 199
0 votes
0 answers
108 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 ...
Coestaris's user avatar
0 votes
0 answers
89 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 ...
Pablo's user avatar
  • 187
0 votes
1 answer
243 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 ...
oleg harput's user avatar
0 votes
2 answers
108 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]]") ...
tonicebrian's user avatar
0 votes
0 answers
114 views

Why is Emacs hanging or seeming like it isin an infinite loop?

In my current Emacs major-mode for Tecplot macro development, I have a few functions defined: (defconst tecplot-macro-mode-syntax-table (let ((table (make-syntax-table))) ;; ' is a string ...
Stephen Alter's user avatar
0 votes
0 answers
730 views

Regular expression for finding 'href' attribute value of <a> HTML element

I need a regex pattern for finding web page links in HTML. For example <a href="https://www.google.com/search?q=elisp+regex+lookaround" ....></a> I can use (?<=href=\").+?(?=\") | (?&...
Ynjxsjmh's user avatar
  • 263
0 votes
0 answers
209 views

Regex search and edit text simultaneously with multiple cursors

I'd like to search for a pattern with regex and simultaneously cut or edit all instances of that pattern. Is there a ready-made function for this? Atom, for example, has one such package - by ...
Sati's user avatar
  • 755