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
1
vote
0answers
25 views

`string-match' and `match-string' in Emacs Lisp [duplicate]

I try to understand the functions match-string and string-match in Emacs Lisp. The manual provides what seems to be (?) a reproducible example: (string-match "\\(qu\\)\\(ick\\)" ...
1
vote
3answers
44 views

imenu to copy the target instead of jumping to it?

Is it possible to use imenu (or another package) to copy the target (specified by a regex) rather than jumping to it? This is an effort for tackling the question: How to list or autocomplete pandoc-...
0
votes
2answers
56 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
0answers
33 views

Ignoring specific files in recentf-mode by their exact filenames

I am having trouble to Ignoring specific files in recentf-mode. (add-to-list 'recentf-exclude "company-statistics-cache.el") On my end, I want to ignore them by their exact file names instead of ...
0
votes
1answer
24 views

Programmatically find-and-replace custom sequence

I need to write a command which will apply to my buffer custom, predefined copy-and-replace sequence. What I have is: (defun custom-processor () "Formats logs to human-readable format" ((replace-...
0
votes
1answer
47 views

How to search with a regexp before point?

I would like to know a function that searches a pattern located before point. re-search-backward is mentioned in the Elisp manual but I do not understand its purpose. Indeed, I do not understand the ...
0
votes
1answer
38 views

How do I build a regexp that enables Emacs to set all words to the left of an equal sign a specific font-lock-*-face?

Following some help provided by Tobias, I am trying to assign a font-lock-keyword-face to all text (:alpha:) to the left of an equal sign (=) in a new Tecplot major mode. I read through the regexp ...
0
votes
1answer
30 views

Regexp: how to search-replace any html attribute in current buffer

Disclaimer: I'm still trying to learn elisp so I have not gotten yet to the RegExp section of the Elisp intro or Emacs manual. I would like to know how to search and replace an HTML buffer that has ...
0
votes
1answer
36 views

thing-at-point does not bound url properly due to backslash in url

I am trying to filter URLs and elisp thing-at-point 'url doesn't bounds a url properly because it has backslashes \in it. I believe that backslashes are unsafe in urls, but that's a separate topic. ...
0
votes
1answer
49 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 ...
3
votes
1answer
453 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" "...
12
votes
2answers
2k views

support for regex look behind and ahead?

I need to perform regex query replace, such that foo in foo bar is matched, but foo in foo baz is not. Normally I would use regex look ahead, e.g. foo(?=bar). However, it seems like Emacs cannot do ...
2
votes
1answer
39 views

Why is the order of : and - important in a regexp character class

Defining the following function (defun windows-path-backwards () (interactive) (skip-chars-backward "a-zA-Z0-9\\\\_-:")) and running it while standing at | in the below text C:\this\path| ...
0
votes
1answer
58 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?
2
votes
2answers
38 views

Not matching a character at the beginning of line

I would like to match lines that have the phrase a test but not start with >. So I want to match This is a test a test this is but not > This is a test I am not sure how to do this without ...
1
vote
1answer
30 views

How to replace strings including `.` (dot) as first character using dired-do-find-regexp-and-replace

(defun my-find-orgfiles () (interactive) (find-name-dired "." "*py")) (global-set-key (kbd "M-n") 'my-find-orgfiles) Than, t to toggle marked/unmarked files (thus marking them all, since none ...
1
vote
1answer
32 views

search-forward-regexp with back reference

I have the following text \begin{comment} TEXT \end{comment} \begin{verbatim} TEXT \end{verbatim} and the regular expression "\\begin{\([^}]*\)} to match the \begin statements and capture the ...
2
votes
0answers
41 views

org-table: hide grid lines

I like how org-mode allows me to quickly create and edit tables. However, I do not like the table's appearance and I would like to modify it. Customizing the face only lets me change foreground and ...
1
vote
1answer
33 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
2answers
72 views

How to get the position after matching and replacing a regular expression (replace-match)?

SHORT How to substitute (nicely) a regular expression by a string in pure elisp, like the unix command sed. LONG I'm using the function replace-match after string-match, but I can't get the right ...
0
votes
2answers
49 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
1answer
149 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
249 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. ...
1
vote
1answer
36 views

How to regex match words? (in multiple languages)

I have a simple regex search which matches [A-Za-z], however I would like it to match other characters which would be used in dictionary words for non-english languages. e.g. ü, Ø, ɵ 人参, while ...
0
votes
1answer
61 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
2answers
68 views

Check whether a string is a date in a specific format, e.g. “%Y-%m-%d”

I have a string and would like to check whether it contains a date in a given date format, e.g. "%Y-%m-%d", with format as for format-time-string. This is for a package and users can configure the ...
2
votes
3answers
161 views

Elisp regex matching - evaluate as region vs as individual sexp gives different answers

Here's a chunk of code: (defvar test-string "bla bla bla 10.10.10.10 bla bla bla") (string-match "[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+" test-string) (message (match-string 0 ...
0
votes
1answer
43 views

How to set a variable that matches different type of strings?

I have these strings: First Type: arXiv:1234.56789 arXiv:1234.56789v1 Second type: hep-th/123456789 hep-th.AB/12345689 hep-th/123456789v1 hep-th.AB/12345689 Belong to the second type even strings ...
4
votes
1answer
95 views

Non-greedy regex group

This is related to my previous question over here. (replace-regexp "\\(\\[\\[\\)\\(zotero:.+\\]\\)\\(\\[.+,[《〈][^《〈]+[》〉]\\)?.+。\\(\\]\\]\\)" "\\1cite-\\2\\3\\4,頁") I'd like to use the above code ...
2
votes
1answer
45 views

can emacs memoize regexps?

This is really a question about implementation rather than anything a user of GNU Emacs would be interested in. Emacs regexps are represented as strings. There is a nice rx DSL for constructing ...
0
votes
1answer
34 views

Limit font-lock highliting to first N chars of line

I write regex for font-lock and I know that the date should appear in first 40 chars of line. How can I limit search beyond some limit? I tried to add ^.\\{0,40\\}XXX but Emacs regex . is greedy ...
2
votes
1answer
45 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 ...
1
vote
2answers
71 views

How to match first character in line after asteriks and space using regex?

For example i have lines: * test1 ** another tests * some other line I would like to match t in first line, a in second, s in third.
0
votes
1answer
48 views

what does the vertical bar “|” mean in sentence-end?

Reference to 12.1 The Regular Expression for sentence-end of Elisp introduction It illustrate alternatives of sentence-end as \\($\\| \\| \\) ^ ^^ TAB SPC and explains: Two ...
0
votes
0answers
47 views

Why is Emacs hanging or seeming like it isin an infinite loop?

In my current Emacs major-mode for Tecplot macro development, I have a few functions defined: (defconst tecplot-macro-mode-syntax-table (let ((table (make-syntax-table))) ;; ' is a string ...
6
votes
2answers
359 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
116 views

How to regexp-search for a word surrounded by spaces

I'm looking at this One use of regexp-quote is to combine an exact string match with context described as a regular expression. For example, this searches for the string that is the value of ...
0
votes
1answer
46 views

Regexp for the inverse of a match

Given a regexp A, how do I derive the inverse regexp B such that given any text exactly one of the two regexes will match it. For example in the below example: (rx (or (group ---regexpA---) ; a ...
0
votes
1answer
99 views

re-search-forward Regex behavior for OR boolean

We usually use \| to depict OR in Regex. Using a\|b as input to Regexp I-search and Occur both gave the desired result. But re-search-forward seems unable to recognize this notation. abcdcba (re-...
2
votes
1answer
44 views

Query replace regexp with a distant match?

I have a single transcript file for a set of course lectures I am watching. After doing some formatting on the file. I have it broken up into sets of lessons where the main heading is the lesson title ...
0
votes
1answer
39 views

Regular expression to ignore a domain in address completion

I read the manual on address autocompletion: mu4e-compose-complete-ignore-address-regexp — a regular expression to filter out other ‘junk’ e-mail addresses; defaults to "no-?reply". I am looking ...
-1
votes
1answer
71 views

Counting number of matches in number of lines for regex search

I have functions that run re-search-forward and gather its output into a buffer. (defun my-search (pattern) "Uses `re-search-forward` to return matching lines." (let ((src) (rslt)) (...
2
votes
1answer
322 views

Yasnippet including backslash

I would like to use Yasnippet to insert the template for a latex inline equation: \( \) The snippet is defined: # -*- Mode: snippet -*- # name: inline equation # key: ineq # -- \( \) But ...
2
votes
2answers
148 views

Regexp for matching quoted strings that may have control characters in them

I am trying to use a regexp to match strings, e.g. a pattern that matches these kinds of quoted strings: "test" or 'test' or 'test with "quote"' or "test with 'quote'" This pattern matches all those,...
0
votes
1answer
29 views

How to find the next match with re-builder?

I built a complicated regular expression with re-builder and see that it works with the matches I want. How can I find all the matches, as I would with C-s in isearch-forward?
2
votes
0answers
50 views

Is point in a regexp?

I am looking for something like thing-at-point for a regexp. For example, I want a function called regexp-at-point-p that will return the matched text if the text around the point matches the regexp ...
2
votes
1answer
48 views

Can Dired query replace use regular expression to rename a group of files?

So I have long list of files that I'm trying to use regex to rename but, it looks like it does not take standard regular expressions. I’m sure I’m just doing this incorrectly. After entering dired ...
0
votes
2answers
100 views

How to match the nondirectory part of a filename with a regular expression?

Whats the correct way to match a filename from a full path using string-match-p. Say I want to check if the file is a git commit message COMMIT_EDITMSG or svn-commit.tmp or svn-commit.3.tmp to pass ...
0
votes
0answers
65 views

Regular expression for finding 'href' attribute value of <a> HTML element

I need a regex pattern for finding web page links in HTML. For example <a href="https://www.google.com/search?q=elisp+regex+lookaround" ....></a> I can use (?<=href=\").+?(?=\") | (?&...
0
votes
0answers
14 views

How to remove all console.logs() from the buffer and also how to comment all console.logs from the buffer?

When I do a regex-replace and replace with the empty string, the console.logs() are removed but the empty lines still remain. How would I remove these empty lines? Furthermore, how would I replace all ...

1
2 3 4 5
8