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
2 answers
32 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-...
user avatar
  • 59
0 votes
1 answer
44 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?
user avatar
  • 523
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 ...
user avatar
  • 501
1 vote
1 answer
106 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.
user avatar
0 votes
4 answers
51 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 ...
user avatar
  • 607
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? ...
user avatar
  • 607
0 votes
1 answer
72 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 ...
user avatar
0 votes
0 answers
43 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.
user avatar
  • 159
0 votes
1 answer
47 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) "...
user avatar
  • 159
1 vote
1 answer
20 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 ...
user avatar
0 votes
1 answer
54 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 ...
user avatar
  • 607
1 vote
1 answer
40 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 ...
user avatar
  • 111
2 votes
1 answer
68 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 ...
user avatar
0 votes
1 answer
24 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]+\\):" ...
user avatar
0 votes
1 answer
32 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 ...
user avatar
  • 101
0 votes
0 answers
21 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 ...
user avatar
  • 101
0 votes
0 answers
30 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 ...
user avatar
  • 967
4 votes
1 answer
75 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 ...
user avatar
  • 385
0 votes
1 answer
42 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 ...
user avatar
  • 353
0 votes
0 answers
14 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 ...
user avatar
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 ...
user avatar
  • 3,435
0 votes
0 answers
23 views

Syntax classes in character alternative regex group

I want to build a regex to match a group of characters which belong either to word (\sw) or to symbol (\s_) syntax groups. Is it possible to use syntax classes in the character alternative group regex ...
user avatar
  • 249
0 votes
2 answers
39 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 ...
user avatar
  • 113
1 vote
0 answers
19 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/...
user avatar
2 votes
2 answers
58 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 ...
user avatar
0 votes
1 answer
41 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 ...
user avatar
  • 193
0 votes
1 answer
33 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, ...
user avatar
  • 1,083
1 vote
1 answer
62 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? ...
user avatar
  • 621
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 ...
user avatar
  • 3,435
0 votes
2 answers
33 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-...
user avatar
  • 620
1 vote
1 answer
86 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 ...
user avatar
  • 621
1 vote
1 answer
76 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)",...
user avatar
  • 123
0 votes
1 answer
32 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.
user avatar
  • 620
0 votes
1 answer
34 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 ...
user avatar
  • 224
3 votes
1 answer
75 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") ...
user avatar
  • 566
0 votes
1 answer
55 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 ...
user avatar
0 votes
0 answers
66 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 ...
user avatar
1 vote
2 answers
118 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 ...
user avatar
0 votes
1 answer
66 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 ...
user avatar
  • 106
0 votes
0 answers
54 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 ...
user avatar
  • 164
1 vote
1 answer
48 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 ...
user avatar
0 votes
1 answer
52 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 ...
user avatar
1 vote
1 answer
71 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 ...
user avatar
1 vote
2 answers
138 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 ...
user avatar
  • 483
1 vote
0 answers
17 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 ...
user avatar
  • 415
1 vote
1 answer
376 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 ...
user avatar
  • 11
1 vote
1 answer
41 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 "\\(" "...
user avatar
  • 7,179
3 votes
2 answers
420 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 ...
user avatar
  • 7,179
0 votes
1 answer
102 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 ...
user avatar
  • 169
2 votes
1 answer
57 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;...
user avatar
  • 607

1
2 3 4 5
9