Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
33 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
19 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
39 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
47 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
63 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
87 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
43 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
40 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
151 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
22 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
47 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
22 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
2answers
168 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
55 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
35 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 ...
4
votes
1answer
36 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
57 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
49 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
639 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
58 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
61 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
48 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
49 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
43 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
26 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
45 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 ...
0
votes
1answer
342 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 ...
0
votes
0answers
16 views

Case sensitive regular expression search [duplicate]

I want to use the re-search-forward function in my Elisp code for searching text. However, it seems to ignore letter case! For instance, when I put the following in my *scratch* buffer: (re-search-...
0
votes
1answer
44 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 ...
1
vote
3answers
61 views

Function that does `M-x replace-regexp` or `M-x occur` with a fixed pattern and replacement strings

I often use M-x replace-regexp and M-x occur with some fixed regexp pattern and replacement string on many files. Doing it manually by opening each file in an Emacs buffer and hitting the keys is ...
0
votes
2answers
34 views

font-lock limits ignored in anchored matchers

I think I might have found a bug in GNU Emacs but I want to check my understanding first. In Search Based Fontification it is possible to specify a function as a matcher. It must obey the contract ...
0
votes
1answer
38 views

Advanced search and replace

I have a file, with a lot of instances of ... fclose(f1); fclose(f2); fclose(f3); ... I'd like to replace these with ... if(fclose(f1)!=0) return 1; if(fclose(f2)!=0) return 1; if(fclose(f3)!=0) ...
0
votes
1answer
57 views

forward-sexp confusion

The following code is an excerpt from the elisp tutorial, section 14.6. (while (re-search-forward "^(defun" nil t) (setq lengths-list (cons (count-words-in-defun) lengths-list))) Placing the ...
0
votes
1answer
30 views

What's the regex to replace <foo> with FOO?

I have a buffer with a lot of instances of words surrounded by '<' and '>', and I want to replace them all with the just capitalized word. E.g. <foo> -> FOO. I read the regex chapter of the ...
1
vote
1answer
171 views

emacs regex to match balanced parenthesis

How can emacs lisp match balanced parenthesis? for example: "foo(bar(),hee()) out()" should be match "foo(bar(),hee())". I try below statement but it doesn't work: #!/usr/bin/env emacs --script (...
0
votes
1answer
117 views

elisp regex newline escape confusion

Shown below is a simple function, which was run in the middle of a text file that contained multiple instances of repeated blank lines. The output of the function is also shown below. The only ...
1
vote
3answers
78 views

Highlight regexp case insensitive

Is there a way to use highlight-regexp in a case-insensitive way? I'm parenthesizing an expression in my regexp and refer to it using \1 later and I want to match this regardless of case. I'm trying ...
1
vote
2answers
60 views

re-search-forward unexpected behavior: case insensitive

According to the documentation of this function, it should be case sensitive. But when I test it out, the result is case insensitive. My emacs version is 25.3.2.
0
votes
1answer
62 views

regex to match abc = abc statement

Use emacs-lisp, how to match the same variable assign statement? for example: below lines should be matched: abc = abc xyz = xyz weeoof = weeoof But below lines should not be matched: abc = abd ...
0
votes
1answer
87 views

How can I specify a regex pattern which matches only lines without a specific string? [duplicate]

How can I specify a regex pattern which matches any line without "lecture" anywhere in it? ".pdf" at the end?
2
votes
1answer
513 views

emacs regex with multiple match for text, in multi line buffer

Following is sample text. Header This is test, and mid line adsf bag a lot of many things shoes> shoes/ This line should not be affected. Neither this line. This is test, and mid line bag a lot of ...
1
vote
0answers
112 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" "...
0
votes
1answer
41 views

use a function to get file in compilation-error-regexp-alist

I have used compilation-error-regexp-alist a lot so I am familiar with the syntax. However for this particular error I need to use a function to get the file because I need wildcards. Here is the ...
0
votes
2answers
39 views

Create strings of a wordlist using replace-regexp

I have a word list with a lot of words that I want to convert into a json file. To do this I need to make them strings and add a comma in the end of all words. I figured it would be nice to use ...
0
votes
1answer
46 views

Using a predefined Regex on a yank

can you please help me to write a small emacs function? This is the first lisp function I am writing and I think I am getting confused with point and mark placement. I want to write a function that ...
1
vote
0answers
54 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 ...
0
votes
1answer
48 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 ...
3
votes
1answer
233 views

Find and remove consecutive duplicated words while ignoring case

I am trying to find and remove duplicated words in a LaTeX file. Right now I am using query-replace-regexp with the regular expression \b\(\w+\)[ #]+\1 where # stands for line-break (C-q C-j). This ...