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
0answers
18 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
28 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
88 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
37 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
124 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
37 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
188 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
28 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
58 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
31 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
16 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
24 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
61 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
41 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
55 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
68 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
29 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
37 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
48 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
23 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
47 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
55 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
81 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 ...
0
votes
1answer
110 views

How to execute elisp commands

Related Question Hi, I want to give an elisp command which extracts the words between two arbitrary symbols. I searched google for elisp and the first item was emacs lisp, which I guess it means a ...
1
vote
1answer
53 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
117 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
155 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
26 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
25 views

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

Suppose I has 2 jsons: { ...
1
vote
1answer
30 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 ...
5
votes
2answers
192 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 ...
1
vote
1answer
75 views

Replacing a string with symbols using font-lock?

I'm trying to make a font lock hook to replace strings of text for a mathmatical notation plugin. So I'm thinking " / " (note the spaces) will turn into " ÷ ", but "/" won't. (It's a package mainly ...
1
vote
1answer
36 views

How query-replace-regexp for all text exact before specific text?

emacs 26.1, windows 10 I have some text. I need to replace all text before WARN I use: query-replace-regexp: .*WARN query replace regexp: RET But I need to delete all text BEFORE WARN. How I can ...
5
votes
1answer
44 views

replacing regular expressions with querying on and functions on match

EDIT: gave more context for my first approach. My goal is to search my notes for strings of the form "4/1/2014" to org-mode timestamps "<2014-04-01 Wed>" (that particular day-of-week may be ...
1
vote
3answers
66 views

How can I search a list of files for content that matches a regexp?

I am trying to write an interactive command that will search a set of files for a regexp. The files are selected programmatically, for example, as a list of files that match some date criteria, or ...
1
vote
1answer
77 views

highlight-regexp groups for syntax highlighting

I want to highlight certain words to a color using highlight-regexp. The words I want to highlight are "fn", "let", "mut", etc. for rust development. The code I have so far is this: (add-hook '...
6
votes
3answers
703 views

Regexp replace to match a string, but not match a superstring

Let's say I want to replace the string "Vector" by "VectorBase", but there are existing instances of "VectorBase". So I would like to omit "VectorBase". What is an elegant way to achieve this? An ...
1
vote
1answer
87 views

How close and exit from buffer *Re-builder*?

emacs 26.1 M-x regexp-builder Input some regexp. Nice. But now I want to close and exit from buffer Re-Builder. How I can do this?
0
votes
2answers
62 views

regexp-builder - no match with correct regexp. Why? [duplicate]

In buffer I has text "ADA-SGD" "ADT-SGD" "ADX-SGD" "AID-SGD" "AMP-SGD" "ANT-SGD" "ARDR-SGD" "ARK-SGD" M-x regexp-builder Input regexp: "\([A-Z]+\)-\([A-Z]+\)" But I get message: No match. Why?
0
votes
0answers
51 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 ...
0
votes
1answer
57 views

How to match a quoted symbol in a string in elisp?

I'm struggling to find a correct regexp to match quoted symbol inside a string: " 'foo " or " 'foo.bar " Any help will be appreciated
0
votes
1answer
36 views

How remove text before “,” (include) in every lines?

suppose I has the next text: -1,0x0 Fireplace HD 1160,0x0 Music HD 719,1 HD -1,1 MUSIC CHANNEL 154,1+1 -1,100% News -1,100AutoMoto TV I need to remove text before "," (include ,) So the result must ...
1
vote
1answer
54 views

How do I align code on dot/period (.)?

I recently switched to emacs. Just wanted to see how it works and if it'll help with productivity. Right now I'm working in Haskell, which means a lot of function composition with . operator. I have ...
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 "...
0
votes
1answer
46 views

Emacs Regexp syntax clarification

I am a bit confused on some aspects of Emacs regexps. Specifically with the paragraph on this page ‘\W’ matches a character which is not within a word ‘\B’ matches characters which are not a ...