Questions tagged [regular-expression]

Regular expressions (often shortened to "regex") are expressions written in a declarative language used for matching patterns within strings.

32 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
27 votes
0 answers
1k views

How does `\zs` interact with syntax matches?

Consider the text: foobarbaz First we highlight the regular expression /foobar/: :syntax match Special /foobar/ Next we highlight the regular expression /foobarbaz/: :syntax match Error /foobarbaz/ ...
Rich's user avatar
  • 31.6k
7 votes
0 answers
376 views

In a regex, why aren't the multi + and {1,} always parsed exactly the same way?

From :h /\+: \+ Matches 1 or more of the preceding atom, as many as possible. And :h /\{: \{n,} Matches at least n of the preceding atom, as many as possible It seems the multi + and {1,} have ...
user9433424's user avatar
  • 6,118
5 votes
0 answers
181 views

Is it possible to use syn match dynamically

I know that syn match can work with the regular expression to do some custom highlight settings. I'm thinking if it can work dynamically. For example, I'm doing a c++ project and I want to highlight ...
Yves's user avatar
  • 1,013
4 votes
0 answers
653 views

Highlight python raw strings as regular expression

I heard someone had set up their editor to highlight python raw strings as regular expressions, e.g. for Django: urls(r'^site1/(\d)*/new$'', ...) Unfortunately my googleing doesn't get me anything. ...
yggdrasil's user avatar
3 votes
0 answers
201 views

How to replace a string not followed by a / character?

How do I replace all occurences of a string that are not followed by a forward slash character in vi (or vim)? I want all occurences of '<[text]', but NOT '</[text]' to be replaced with '<db:[...
Lidia's user avatar
  • 131
2 votes
0 answers
119 views

Can Ultisnips regular expression match forward?

The question may be also phrased as, can Ultisnips regular expression match after the current cursor? My goal is to have a postfix of curly bracket for LaTeX subscripts. Say I want to type a_{bcd}, ...
Frid Fu's user avatar
  • 21
2 votes
0 answers
93 views

Use different regex engine for different use cases/plugins

By default re=0, however I'm running into those issues: re=1 makes ctrlp.vim much faster re=2 makes vim-jsx-pretty much faster And somehow re=0 can't seem to get those right for me. Is there a way ...
foo's user avatar
  • 121
2 votes
0 answers
582 views

Regex to remove newline; works in one vim instance, but not another

Trying to remove newlines with a regular expression (not shift-j). I have one vim install where :g/conf/s/\n// works as intended, removing a newline from all lines containing 'conf'. I have a ...
David Fleck's user avatar
2 votes
0 answers
244 views

custom fold expression to fold functions

I would like to create a custom fold expression for functions of the form x <- function(a,b,c) { ... ... body ... } where the lines starting from function(...) until the closing brace are ...
husB's user avatar
  • 2,038
2 votes
0 answers
36 views

Substitute regex group in prompt when replace with confirmation

I am using vim to replace with simple regex: %s/Foo\(.\)/Bar\1Biz/gc I wanna to confirm each occurence and Vim asks: replace with Bar\1Biz (y/n/a/q/l/^E/^Y)? Is it possible to substitute group (\1) ...
Deffe's user avatar
  • 21
2 votes
0 answers
179 views

How to match patern inside a syntax region start pattern?

Python group regexp has this syntax (?P<idGroup> ... ), where: (?P<idGroup> is the beginning of a region. ... is the content of the region. ) is the end of region. I highlight start ...
user4500's user avatar
1 vote
0 answers
68 views

\zs not working in syntax file?

Udated 2023-09-11: Changed example to asterisk as it is simpler and the question now refers to \zs instead of \ze as \zs seems to be the issue. I am trying to adapt the VIM Markdown syntax file so ...
StaticNoiseLog's user avatar
1 vote
0 answers
39 views

Interaction between zero-width matchers and backreferences

Take a file with the following text as a workbench. hello world hello world With the cursor at the beginning of the line, here's how \1 interacts with \(…\), \@=, and \@! # regex matched text text ...
Enlico's user avatar
  • 2,184
1 vote
0 answers
258 views

Bulk file rename in Vim Visual Block Mode

I am using VIM Renamer plugin to bulk rename files, I want to replace E008_r5_Haz_Area_Class NAT GAS.pdf E009_r4_Haz_Area_Class.pdf E010_r4_Haz_Area_Class MP STEAM.pdf E011_r3_Haz_Area_Class.pdf ...
nirag's user avatar
  • 11
1 vote
0 answers
113 views

Jump between all the matchadd matches for a group?

One can use the matchadd function to add to groups of matches that will be highlighted in the VIM editor. But how does one jump between the matches within a specific group?
leeand00's user avatar
  • 3,491
1 vote
0 answers
338 views

Multi-line regex with specific beginning and end?

I can't seem to find the answer to this anywhere. I'm trying to get started with include-search, and since I'm working in golang right now, I'm trying to get vim to include a set of imported files. E....
Harv's user avatar
  • 219
1 vote
0 answers
103 views

search and replace: remember case in substitute

I have to change strings: fetchrandomData to fetchReportingData FETCH_RANDOM_DATA to FETCH_REPORTING_DATA I can change ca_z and CA_Z to ca_t and CA_T respectively with command: %s/\v([Cc])([Az])(_)?...
HarshvardhanSharma's user avatar
1 vote
0 answers
47 views

How to specify Perl encoding in Vim?

For a buffer containing text "กขค" with UTF-8 encoding: :perldo s/ข/x/g => "กxค" but :perldo s/[ข]/x/g => "xx�xxxxx�". How to specify Perl's encoding? Note: Currently I have to use %:!perl -C -...
aggu's user avatar
  • 11
1 vote
1 answer
67 views

Syntax - Match word based on a previous match

I want to highlight all words that have been matched in another syntax region. Using something similar to regex capture groups, for example given a file: {highlightme} asda asasd asd asd as ...
Seph's user avatar
  • 163
1 vote
0 answers
196 views

Disable regex searching in specific windows

I usually have about 4 or 5 windows open in Vim. Currently - one of my files is very large(in size) - a CPU cache trace. Every time I search with "/", vim searches all windows before returning the ...
The Yoshter's user avatar
1 vote
0 answers
40 views

How to access syntax elements

I try to inline one syntax in another syntax (to be explicit: CSS in JS template strings). I'd like to build on top of the existing CSS definitions and not create new ones. Question: Is it possible ...
fleischie's user avatar
1 vote
0 answers
336 views

Matchit Plugin: issues when resetting regular expressions in "b:match_words" for detecting Matlab file keywords

I'm trying to implement a custom regexp string to be used by matchit.vim for identifying matching keywords that can be jumped between with %. I found a utility from FileExchange (in the ftplugin ...
Luke Davis's user avatar
  • 1,397
0 votes
3 answers
50 views

Strange result for grouping replace in a line

The file contains only one line: four_blank_space + "TE:" + one blank space + "trailers" + one blank space I write a grouping replace: :1s/\(\s\+\)\(.\+\):\s\+\(.\{-}\)\(\s\{0,}\)...
showkey's user avatar
  • 1,120
0 votes
2 answers
354 views

Regex to select indented lines preceded by one top blank line not working in Vim

I made the regex: /^\n\t(\n|.)*?\n$/gm (prepended with \v inside Vim) to select consecutively indented lines (with tab) separated by a top blank line. But while it works in other languages it doesn't ...
ThisMakesMeGray's user avatar
0 votes
0 answers
156 views

Regex multiple lines search, matched, but highlighted only what initially is on screen

Let's say I have the following fantasy code // a long definition of a structure struct long_struct { ... }; There are tons of multiple lines inside such block of code. It cannot be displayed ...
haxpor's user avatar
  • 121
0 votes
0 answers
157 views

Matching patterns in autocommands

I'm trying to match a particular path pattern for an autocommand. I have this: au BufRead *.md if expand('<amatch>') =~ "/path/to/dir/[0-9]" It successfully matches, eg. c:\soemthing-...
Tom's user avatar
  • 31
0 votes
0 answers
56 views

How to add spaces upto a fixed column before a certain character in the line

Suppose I have a line in which the dot appears. Then, I want to add spaces upto fixed number of columns to indent my code. Also, I can't install plug in. Is there any way I can do with just command ...
RAHUL KUMAR BUDHWANI's user avatar
0 votes
0 answers
313 views

syntax highlight regex not matching

I am writing a plugin where a certain filetype must possess their own syntax highlight. Therefore I have created . ├── ... ├── plugin └── syntax and syntax/newfiletype.vim containing syntax clear ...
gented's user avatar
  • 109
0 votes
0 answers
186 views

Spelling mistake regex

I have a large text file of an OCR'd book where many words have been broken and hyphenated at the end of a line. Eg. In his newest book of language ex- ploration, Professor Asimov ranges over I can ...
Tom's user avatar
  • 1
0 votes
0 answers
285 views

can not make this regex pattern work in "very magic" mode

I am trying to construct a regex pattern to match characters inside two # characters. For example: #abc#bc#cd# I would like to match abc, bc and cd. The following regex without using magic mode ...
jdhao's user avatar
  • 1,113
0 votes
0 answers
36 views

Search and replace any number separated by : trailing with number or alphabet separated by . and / or - or _

Search pattern examples "0:4.10.5-5.el7" "0:0.7.7-13.20120626.ov7" "6:4.14.8-6.po7_3" How to search and print all occurrences like above patterns where the first number can be any number ranging ...
hellomister's user avatar
0 votes
0 answers
152 views

How to pass '\v\C[pattern]' into the built-in match() VimScript function

I am attempting custom fold logic as my first VimScript. What works for me: USING VERY MAGIC (\v) and explicit CASE SENSITIVE (\C), find python comments in foo.py that begin with hash, then Roman ...
Charles Kong's user avatar