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
24 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 ...
0
votes
1answer
141 views

Custom search function for dictionary lookup

I have a plain text dictionary in which each headword is matched by ^# \(† \)?headword, How can I make a custom search function that relieves me of typing the whole regex every time I want to look ...
0
votes
1answer
227 views

Left-align org-mode like FoldingText… Regexp?

I posted this question on stackoverflow earlier, but perhaps this is a better place for it? I am looking for a way to left-align text in Org-mode so that the paragraphs line up like in FoldingText. ...
0
votes
1answer
55 views

Removing and adding newlines around expressions

I am in the process of formatting a couple of hundred markdown files and am trying to automate that process. I am having two problems, but I guess I can ask two questions ;) Goal I am trying to ...
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 ...
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- ?
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 ...
6
votes
2answers
252 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 ...
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
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 "#...
0
votes
0answers
16 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 ...
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:]_]+ ...
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 ...
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 ...
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 ...
2
votes
1answer
57 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
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
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?
1
vote
1answer
28 views

Adding a line to the beginning of every function in a (ruby) source code file

Supposed I have a source code file (classes) and some methods in that file. see https://github.com/railstutorial/sample_app_rails_4/blob/master/app/controllers/users_controller.rb I want to add a "...
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
2k views

Whitespace and newlines in regexps?

For a number of reasons (one of them my lameness) I get extremely confused when it comes to whitespace and newlines in regexps. Say for example that I want to search for an equal sign (=) followed by ...
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 ...
2
votes
1answer
107 views

Tramp Unable to Recognize Remote Prompt

I have been trying to get tramp working and I am having issues with recognizing the remote prompt. Unfortunately, I cannot change the remote prompt because it is dictated by my school. I have tried ...
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 ...
20
votes
2answers
171k views

What is the regex to match a newline character?

In Emacs regex, \n doesn't match a new line character \n. Am I correct that $ matches the position between a new line character and the character right before the new line character. e.g. for a ...
4
votes
1answer
224 views

Equivalents to vim \zs and \ze?

In vim, all instances of an apple tree can be replaced by an orange tree with :%s/an \zsapple\ze tree/orange/g. \zs and \ze mark the start and end of the passage to be operated on. Is there something ...
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
63 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
94 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 ...
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 ...
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, ...
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
2answers
124 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
157 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 ...