Skip to main content

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.

55 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
176 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.9k
4 votes
0 answers
124 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
  • 151
4 votes
1 answer
2k 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,829
4 votes
0 answers
162 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
  • 33.2k
2 votes
2 answers
70 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,069
2 votes
0 answers
107 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
118 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
  • 181
2 votes
0 answers
369 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,907
2 votes
0 answers
85 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
0 answers
17 views

How to grab previous word from buffer in custom company-mode backend?

I want to make my own backend for company-mode. It must be context sensitive: completion list should be build based on previous word in editor. When I write: git res|, list should contain word "...
BPS's user avatar
  • 113
1 vote
1 answer
154 views

replace nth-match of a regexp in a string

I'm looking for a function that can replace the nth-match in a string. Here's an example. 2 is the index of the nth-match, [0-9]+ is the regular expression to search. foo is the replacement and "...
Rodrigo Morales's user avatar
1 vote
0 answers
47 views

How can I search for CamelCase words in a buffer using Elisp?

How can I find CamelCase words in the buffer using Elisp? Have started with the following but the pattern does not cover all situations of CamelCase. (defun detect-camel-case-words (string) "...
Dilna's user avatar
  • 1
1 vote
1 answer
124 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
34 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
24 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
  • 517
1 vote
1 answer
351 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
160 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,400
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
  • 4,174
1 vote
0 answers
81 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
81 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
431 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
157 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
  • 335
1 vote
0 answers
50 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
  • 217
1 vote
0 answers
338 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
  • 919
1 vote
0 answers
72 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
87 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.9k
1 vote
0 answers
111 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
  • 1,119
1 vote
0 answers
297 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
46 views

replace-regexp-in-string inserting rather than replacing at some matches

This is my first question. My searches through answers to (some of the) similar questions hints that I likely have to educate myself on Match Data, but I'm asking here now anyway. Anyway, I have a ...
ramsay's user avatar
  • 1
0 votes
0 answers
15 views

counsel-M-x search for command names optionally beginning with my:

Goal Use counsel-M-x to browse commands that begin with a particular character, except that they may be optionally prefixed by my: Example counsel-M-x >> ^org matches commands beginning with org ...
user615536's user avatar
0 votes
0 answers
71 views

Use different font for math fragments in org mode

How do I use the fixed-pitch font for math fragments in org-mode buffers? I.e., I want to use a monospace font for all strings of the form \(...\) or \[...\], where ... may include newline characters ...
A is for Ambition's user avatar
0 votes
0 answers
44 views

Regexp searches that repeatedly cover expressions

I'm just going through an old Latex-text I've written and wanted to use regexp-replace to make any pair of brackets containing at least one other pair of brackets into a \left(.*\right)-expression. ...
Alexander Praehauser's user avatar
0 votes
1 answer
129 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
39 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
  • 676
0 votes
0 answers
26 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 ...
Dilna's user avatar
  • 1
0 votes
0 answers
110 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\\)" "" ...
Dilna's user avatar
  • 1
0 votes
1 answer
203 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
72 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.
Dilna's user avatar
  • 1
0 votes
0 answers
134 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
118 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
  • 320
0 votes
2 answers
128 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
131 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
849 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
  • 313
0 votes
0 answers
229 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
  • 815
0 votes
2 answers
208 views

How to write regex to change the go keywords color?

I want to change the color which in package import go defer in go-mode ,need a regex..these code only change the pacakge word color (defface my-font-lock-gokeyword-face `((t (:foreground "#...
xiaodong huan's user avatar
0 votes
0 answers
86 views

Has matches , but re-builder print "No matches"

Emacs 26.1 In scratch buffer I has text KRW-EOS hel-how hello-how-ar h-privet kak-del 123-567 aaa-bbb AAA-BBB AAAA-BBBB AAA-BB AA-BBB A-A AAAAAAAAAA BBBBBB AAA BBB ZZZ-YYY M-x regexp-builder Input ...
a_subscriber's user avatar
  • 4,174
0 votes
0 answers
178 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 ...
Lupino's user avatar
  • 121
0 votes
0 answers
186 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 ...
lo tolmencre's user avatar
0 votes
0 answers
77 views

Why does looking-at ignore the *?

I seem to have some misunderstanding with looking-at. This is my test function : (defun lkat () "interactive looking at" (interactive) (if (looking-at "^\\s-*") (message "yes") (...
Markus's user avatar
  • 481