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.

39 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
137 views

LaTeX-aware sentence endings?

Q: how do I define sentence endings to be LaTeX macro-aware? I'd like backward-sentence and forward-sentence to be smarter about LaTeX macros -- particularly \footnote -- when working in LaTeX ...
3
votes
1answer
446 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" "...
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 ...
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
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 ...
2
votes
0answers
372 views

How can I use more than 9 regex capture groups in Emacs Lisp?

I have to do a regexp replacement with more than 9 capture groups. How can I do it? Here there is my code (with \\10 and \\12 that they do not work as I expected to): (perform-replace "\\\\href{...
2
votes
0answers
76 views

Upper/lower regexp char classes and current-case-table

I seem to have a problem with [:upper:] [:lower:] and Unicode characters. This test fails: (ert-deftest haskell-upper () (set-buffer (get-buffer-create "*haskell-mode-buffer*")) (insert "Ż") (...
2
votes
0answers
248 views

org-mode smart-quotes (probably prb with the regexps)

I have a problem with org smart-quotes. There are two cases that don't seem to be covered by the standard regexps to identify quotes, namely in the case '" and the case "'. The double quote in both ...
1
vote
0answers
47 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 ...
1
vote
0answers
34 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$, ...
1
vote
0answers
153 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 ...
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
0answers
112 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 ...
1
vote
0answers
33 views

JavaScript regular expressions in re-builder

Is there any package that allows me to input regular expressions following the JavaScript syntax (or even Perl Compatible Reg. Exp.)? I want to have an interactive regular expression builder (like re-...
1
vote
0answers
48 views

How to set ps-end-cut-regexp

I often use ps-print-buffer to print out files, but I don't want the first few lines of the buffer to be printed. Here's the beginning of the buffer: # -*- mode: org; -*- # Last updated: <2017/12/...
1
vote
0answers
167 views

Help Aligning a Pattern with `align-regexp`

How can I use M-x align-regexp to align by // All ; after // All , within [] after // For example: With text: Line 1 ; B // Comment 1 [11, 22] ; Comment 2 [3333, 4] Line 2 C // Comment 3 [3, 55] ...
1
vote
0answers
55 views

using re-search-forward in yas-snippet

I'm trying to develop a new yas-snippet for expanding a common c++ log function I use a lot. The first parameter to the LOG function can be guessed by searching for existing LOG calls in the buffer. ...
1
vote
0answers
75 views

Good way to match symmetric delimiters

I am trying to match $$ resp $ pairs to switch into latex-mode via polymode in a markdown file. $$ is the delimiter for displayed math in this case and $ for inline math. I know that this is not a ...
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
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 ...
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
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 ...
0
votes
0answers
63 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 ...
0
votes
0answers
52 views

Regex search and edit text simultaneously with multiple cursors

I'd like to search for a pattern with regex and simultaneously cut or edit all instances of that pattern. Is there a ready-made function for this? Atom, for example, has one such package - by ...
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 ...
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
0answers
29 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 ...
0
votes
0answers
62 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
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 ...
0
votes
0answers
81 views

Interactively matching beginning of region

Short version: If i bound the scope of a search/replace to a region in the buffer (via the second/third optional argument of search-forward and its derivates), how can i match the beginning of that ...
0
votes
0answers
131 views

Prettify string, find by regex

I want to replace the regular expression `.*` by bolding .* and not displaying the backticks. So I want `elem` to become elem I looked into these questions about how to prettify strings rather than ...
0
votes
0answers
70 views

Why does looking-at ignore the *?

I seem to have some misunderstanding with looking-at. This is my test function : (defun lkat () "interactive looking at" (interactive) (if (looking-at "^\\s-*") (message "yes") (...
0
votes
0answers
56 views

Can you use a regexp in an abbrev definition?

I want to replace words like 1st with 1^{st} and 102nd with 102^{nd} while typing in emacs. Basically I want to replace things that match this: "\([0-9]+\)\(st\|nd\|rd\|th\)" with this \1^{\2} as I ...
0
votes
0answers
168 views

Match regexp group

I am trying to modify org-wikinodes.el to match any org-mode headline (not just camelCase text. So I have replaced the default regular expression with: *\\s-\\(.+\\) This works. But in order to link ...
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. ...
0
votes
0answers
122 views

Need help with a snippet

Can someone help me with this snippet? I found it here # -*- mode: snippet -*- # name: jsdoc comment # key: doc # -- /** * $0 `(save-excursion (let* ((pos-fun (re-search-forward "\\<function\\s-*(...