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
1answer
16 views

Accessing regular expression groups outside a buffer

The code from here accesses groups of a regular expression match in a buffer in interactive mode: (let ((re (concat "\\([ \t]*" org-clock-string " *\\)" "\\([[<][^]>]+[]&...
0
votes
1answer
7 views

Regular expression gives different results as variable and as literal

In the Emacs *scratch* buffer, I get different results when I use the same regular expression as a variable compared to a literal: (setq splitter-string "9:20") "9:20" (string-match "[0-9]?[0-9]:[0-...
0
votes
1answer
25 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 ...
1
vote
0answers
28 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 ...
4
votes
1answer
90 views

Is [:space:] same as \s-?

Emacs 26.1 In regexp help https://www.emacswiki.org/emacs/RegularExpression has the next regexp: [:space:] a whitespace character Is this a same as: [ \t\r\n\v\f] and same as \s- ?
0
votes
1answer
58 views

Replace full-width numerals with half-width numerals

I'd like to convert numerals from half-width to full-width characters with a simple regex search and replace as follows: replace-regexp-in-string regexp rep string &optional fixedcase literal ...
0
votes
1answer
23 views

How to include lines in a regular expression search which might not be present?

I'm using a regular expression search which is working as expected. This searches for unified diff file entries and works as expected. (re-search-forward (concat ;; Prefix '+++ '. "^" "...
0
votes
0answers
17 views

Matches from re-builder different from re-search-forward and search-forward-regexp due to double backslash [duplicate]

Following Org mode refiling gobbles a newline and absorbs the next heading where Org mode refiling has gobbled some of the next heading, I want to search for those gobbled headings where the stars are ...
0
votes
1answer
25 views

Replace lines with ( with :( by regex-replace

I have such a snippets: Exercise 2.32. We can represent a set as a list of distinct elements, and we can represent the set of all subsets of the set as a list of lists. For example, if the set is (1 ...
1
vote
1answer
31 views

Adding `**` to head of lines with numbers in the beginning

I have the following contexts: 4. Pattern-Matching Conditional: How to use pcase and friends. 5. Iteration: while loops. 6. Generators: Generic sequences and coroutines. and intent add ** to the ...
1
vote
1answer
48 views

Fold all regexp matches

I'm working on email templates using web-mode, which – alas – requires inline styling galore… many of my opening tags won't fit on a single line even on a 4K-Display due to the massive amount of ...
3
votes
1answer
129 views

Simplest Pattern for matching Identifiers in complex Regular Expressions?

I frequently need a regular expression, that approximately matches identifiers in a given environment. Ignoring the "must not start with a number" requirement, this would mean e.g. [[:alnum:]_]+ ...
2
votes
1answer
49 views

Match any character in a regexp (e.g. `string-match`)

In perl when matching multi-line strings you can add the s modifier /.../s that will change the semantics of . to match also newline. Is there something similar for string-match? Or is there a ...
0
votes
1answer
26 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 "#...
1
vote
1answer
61 views

How to understand paragraph-start variable regex

Problem When i evaluate the paragraph-start variable in the major mode lisp-mode, it has the following value "^L\\|[ ]*$" In emacs the ^L is displayed in red color so I'm not sure if there is ...
0
votes
0answers
20 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 ...
1
vote
0answers
33 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 ...
1
vote
0answers
47 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$, ...
2
votes
1answer
103 views

elisp regular expression build problem

I have the following line : mod_name func_name /users/username/workspace/path_name/file.c 283 I wanted to capture the 3rd and 4th entry in this line, I am able to do that using regular expressions ...
1
vote
1answer
25 views

Basic quote regex for font-locking?

I have my own font locking that highlights quotes in comments eg. /* Some comment 'this is quoted' * more 'text in an escaped \` quote'. * Plurals such as Moe's or Joe's should work too. */ ...
0
votes
1answer
42 views

How to count matches of all buffers?

I am looking for a way to count regexp matches across all buffers. count-matches can count in current buffer. How to count across all buffers?
5
votes
1answer
143 views

Folding custom regular expressions in emacs?

Consider a pattern/regular expression I will call reg which matches multiple times in an emacs buffer. I want emacs to recognize all matches for reg and replace (temporarily, like folding) each ...
1
vote
1answer
50 views

Regex: Don't Match Text Between Curly Braces (LaTeX Commands)

I've been using pandoc and emacs to convert beamer presentations to markdown format. In the beamer presentations we highlighted certain code in example code blocks red. Pandoc has left me to get rid ...
4
votes
1answer
195 views

How to apply arithmetic operators to query-replace-regex

I am attempting to replace all "begin" and "dur" attribute values in my SVG code with one-tenth of (or ten times) their current values, in order to speed up/slow down animation for testing/debugging ...
1
vote
1answer
40 views

Org mode regex search view

Upon reading Search View It state that You can incrementally adjust a boolean search with the following keys [ Add a positive search word ] Add a negative search word { Add a positive regular ...
2
votes
2answers
61 views

Grep multiple lines in a directory

I have a regular expression that can match several lines of text, and I want to use it to search every file in a directory. The problem is that standard regrep command works line by line, so this ...
6
votes
2answers
1k views

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

I'm working with strings which may have any number of prefix and suffix spaces, tabs, newlines, etc. Currently I have this: (replace-regexp-in-string "^[^[:alnum:]]*\\(.*\\)[^[:alnum:]]*$" "\\1" ...
1
vote
1answer
48 views

How to paste a multiline regex from re-builder into `replace-regexp`

I built with M-x re-builder a regex to match empty quoted lines in emails. In read syntax it is: "^>\\s-*\n>" How can I copy this regex in re-builder, so that I can paste it in the first ...
1
vote
2answers
18 views

Start by - and and by whitespace

I want to select (by regexp) only text that start by - and end by whitespace here text: test-hello how-are again ok maybe good but-some not good but-what about this I use this regexp: -.*\s- but ...
0
votes
1answer
25 views

Can't mark only spaces

I want to select by regexp only spaces. Here text: test-hello how-are again ok maybe good but-some not good I use regexp [:space:] but it's not work:
0
votes
2answers
64 views

How replace either of two words using a regexp to find them?

Text How are you? I'm just fine. I need to add some suffix to the next words: are and fine. I try this: \(are\)|\(fine\) but it doesn't help.
0
votes
2answers
49 views

How to chain isearch-forward-symbol-at-point and query-replace-regexp into a single keybinding?

I'm looking to create a keybinding that will perform the following shortcut: call isearch-forward-symbol-at-point call query-replace-regexp It's basically a shortcut for the following key combo: M-s ...
1
vote
2answers
57 views

How can I edit my function to work to kill lines not matching RegExp [duplicate]

I made a function to filter unimportant lines from a CSS file I copied. I only want lines with the words "color" and "background" to remain in my buffer after the point the function is run. When I run ...
2
votes
1answer
39 views

Finding English Letters in a multilingual document

I have a document mainly Persian with English/French/German characters here and there. I want to append a command before Latin word(s) and a } at the end. Do you think it could be done in emacs? ...
0
votes
0answers
95 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 ...
0
votes
0answers
35 views

C++ Windows Compilation Error/Warning Regexp

I am trying to setup a compile for Emacs on Windows using the CL C++ compiler provided by Windows with Visual Studio 2017. https://imgur.com/a/M80uTWH as can be seen from the above image, however, ...
3
votes
1answer
45 views

pcase matches with rx but not with regex

(rx bos (1+ (in "0-2")) eos) evaluates to "\\`[0-2]+\\'", so I expected these two functions to be equivalent: (defun with-rx (s) (pcase s ((rx bos (1+ (in "0-2")) eos) "matched") (t "not ...
2
votes
1answer
58 views

what does grave accent ` and aposrophe ' do in elisp regular expression?

I use C-h v to check the doc about this variable org-agenda-file-regexp. It says it is a variable defined in org.el. Its value is "\\`[^.].*\\.org\\'" What is the meaning of grave accent ` and ...
1
vote
1answer
24 views

query replace content within brackets

I was trying to re-structure my latex document but I failed to do it in a single query regex. My goal was to the following transformation: \item[root] → \item \textbf{root} I tied grouping the ...
1
vote
1answer
57 views

How to match an expression under the cursor?

I'm trying to match an expression under the cursor. In this case it happens to be reStructuredText, however I don't think that's such an important detail. :role:`Some Content` While this works, it ...
1
vote
2answers
125 views

Emacs replace-regexp reference the match in the replace argument

Is there an easy way to use replace-regexp to do something like: XYZ001 XYZ002 XYZ003 to 'XYZ001' 'XYZ002' 'XYZ003' i.e. replace-regexp XYZ* 'XYZ*' Is replace-regexp the the wrong tool for the ...
2
votes
1answer
158 views

How to correctly write regular expression to match ASCII control chars

I would like to to create a regular expression in elisp (in the standard 'read' form) to match extended ASCII chars the same as PCRE does: ^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$ So, I'm ...
1
vote
1answer
68 views

Elisp expressions in projectile-replace-regexp

I need to execute a regular expression with case conversion in a entire project. If I run query-replace-regexp in a single file informing '\([A-Z]+\)' and '\,(downcase \1)', it works as expected. But ...
1
vote
1answer
228 views

search and replace double space

I've only recently started using emacs, for professional reasons. I'm trying to replace all double spaces in a text file by single ones using regex. In C-M-s the expression \s-\{2\} matches two spaces ...
3
votes
1answer
163 views

regexp: exclude repeated characters for highlight - hi-lock-mode

I want to search using regexp to capture plain text. I want to capture passages that begin with opening quotation marks and end at the end of the paragraph, and even though the quote continues onto a ...
2
votes
1answer
31 views

How to replace a digit by a letter?

I want to replace some digits by letters such that 1 ---> a 2 ---> b ... In emacs I have tried the following replacement: M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ ?a \#1)) RET ...
0
votes
1answer
49 views

Regexps: 2 strings without a character in between; 2 chars w/o a string in between - Stack overflow in regexp mapper

I am trying to search through some babyl files for errors. The files are email messages that appear between ^L and ^_ (Control-L and Control-_), with a special string "\*\*\* EOOH \*\*\*" in between, ...
0
votes
1answer
26 views

Select text on first line AND another text on third line by regexp

Suppose I has 2 jsons: { ...
1
vote
1answer
33 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 ...
6
votes
2answers
253 views

How to transpose two arguments of a function call for C family languages?

How to swap two arguments for C function calls? eg: my_function(foo, bar, baz); ~~~~~~~~~~~~~^ (cursor location) Should be transposed to the right to make: my_function(bar, foo, baz); The simple ...