Questions tagged [regular-expression]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
34 views

Using variable to find & replace while incrementing number with regex

Given the following text: 0 : Container( alignment: Alignment.center, padding: const EdgeInsets.all(24.0), child: RichText( text: TextSpan( ...
AdjunctProfessorFalcon's user avatar
0 votes
1 answer
23 views

Pattern works with / but it does not work when used in filter function()

I want to extract the the substring Python 3.11 from the strings like Python 3.11.2.release0 (i.e. I want to extract Python followed by the first two digits separated by a .). Such longer strings ...
Barzi2001's user avatar
  • 416
0 votes
2 answers
34 views

Capturing a group in a pattern used in a Vim autocmd

I need Vim to ignore the .tmpl file extension to enable syntax highlighting. How can I rewrite this: autocmd BufNewFile,BufRead *.lua.tmpl set filetype=lua to be more general? I want to match the lua ...
Nikita M. Grimm's user avatar
0 votes
1 answer
17 views

How do I include the match number when searching and replacing in vim using regex?

I'm trying to make my struct's members accessible through an index like an array, so if I have a struct like this in rust: pub struct SubjectsProgress { pub sword: i32, pub lance: i32, pub ...
Apoqlite's user avatar
  • 103
1 vote
1 answer
73 views

Why very magic flag can't take effect on character = in substitute command?

We can see the explaination on very magic :With very magic, all ASCII characters except 0…9, a…z, A…Z and _ become a a special meaning. In this mode, searching for text becomes very magic. When you ...
showkey's user avatar
  • 1,056
1 vote
1 answer
61 views

What does \_. means in Vim?

what does \_. means in vim ? explain to me character by character Response from chatgpt: In Vim regular expressions, \_. is a sequence that represents any character including a newline. Here is an ...
andrew_ysk's user avatar
0 votes
1 answer
37 views

Apply normal command to all regex matches on the same line

This comment convinced me that I don't need multiple cursors, however, it's missing one feature that multi-cursor can do, which is to perform actions on multiple regex matches on the same line. :g is ...
Wong Jia Hau's user avatar
0 votes
3 answers
42 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,056
2 votes
2 answers
591 views

Why [\w-] can't match \w or -?

[ab] matches any of a or b ,\w matches any word character (alphabets, digits, underscore). I find that [\w-] can't match \w or - .In order to convert Sec-Control into "Sec-Control".The ...
showkey's user avatar
  • 1,056
1 vote
1 answer
83 views

How to match a specific column position till the end of line?

^ denote the beginning of the line ,$ denote the end of the line. Suppose that there is a line in my vim: this is a test line test line. I want to remove all the characters from the 20 th character ...
showkey's user avatar
  • 1,056
0 votes
1 answer
25 views

Use regex pattern as argument to function

I want to be able to pass a plain regular expression like so autocmd BufReadPost * call TextEnableCodeSnip('bash', /^hello/, /^world/, 'SpecialComment') To a function and use it within as a regular ...
drcomputer's user avatar
0 votes
1 answer
39 views

Simplifying a complex regex

I am programmatically generating a very lengthy regex expression in a lua script I'm developing. It works, but at 960 characters, I can't help thinking it can be simplified a bit. However, I can't ...
Phil R's user avatar
  • 411
0 votes
3 answers
43 views

Replace all occurrences of ' 1 ' with matched text in one line

I've got a text file, containing following lines <a href="tg://proxy?server=radan.rooznameh.etellaate.rooz.romatism.sbs&port=443&secret=...
wl2776's user avatar
  • 360
0 votes
1 answer
30 views

Substitute in multiple isolated parts of a string

I have this string: b'32^"Strings" c32 d32 c32 b32 r8. \break I want to replace [a-z] (except r) with r and remove ' everywhere outside "..". I want to ignore \break. Final output ...
kargirwar's user avatar
  • 145
1 vote
1 answer
82 views

How to use alternation operator in ripgrep + vim?

I have the following in my .vimrc which (I believe) makes :grep within Vim use rg: if executable('rg') set grepprg=rg\ --no-heading\ --vimgrep\ --hidden\ --case-sensitive\ --ignore-vcs\ --glob\ '!....
Aaron Parisi's user avatar
1 vote
0 answers
58 views

How do I turn on `\v` by default for Vim/Neovim regexes?

After years of using Vim and then Neovim, I still find myself forgetting to escape parenthesis and the | character when I intend to use their special behaviour: If I want to search for "this"...
Flimm's user avatar
  • 2,002
0 votes
1 answer
19 views

How can I match 0 or more atoms and never give it back to backtracking?

I've noticed that matchstr('hello*', '\v\a+\*=\ze%(\A|$)', 0) returns hello, which means that \*= is not matching the literal *. I thought I had got the syntax wrong, but I think I've not, because: ...
Enlico's user avatar
  • 2,056
0 votes
1 answer
213 views

Regex for replacing parameter values in a URL (values between = and &)

I have a large list (100,000+) of URLS with parameters like so: https://www.example.com?a=b&1=2&me=you https://www.example.com?a=b I'm using VIM need a regex to replace all values with ...
ex7lted's user avatar
  • 37
0 votes
2 answers
127 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
1 vote
1 answer
30 views

Return last match of matchstr within single line

I have a little class/function detector in my .vimrc displaying, in my statusline, the python class/function my cursor currently is inside of. I am currently trying to adapt it for C++ source files, ...
Feffe's user avatar
  • 1,739
0 votes
2 answers
63 views

How can I chain together regular expression substitutions

I am trying to write a command that changes author lists of the form R. L. Rivest, A. Shamir, and L. Adleman Into one nice for BibTeX, namely: Rivest, R. L. and Shamir, A. and Adleman, L I have ...
sdpoll's user avatar
  • 103
2 votes
3 answers
323 views

Regex: is this a Vim bug or my bug?

I have a syn match item like this: syn match txr_num "[+\-]\?\([0-9]\|[0-9][,0-9]*[0-9]\)\?[.]\([0-9]\|[0-9][,0-9]*[0-9]\)\([eE][+\-]\?[0-9]\+\)\?" Given an input like 1.234e13 it matches ...
Kaz's user avatar
  • 461
0 votes
2 answers
142 views

How would I remove all text outside single quotes in VIM using regex?

I'm using a vim script to quickly edit some text. I have a large list from an api endpoint that looks like this: save: presets.api + 'campaign/:campaignId/settings', ...
ex7lted's user avatar
  • 37
1 vote
2 answers
67 views

How to create a range command that substitutes characters with grouping and back references?

The use case is to copy citations from pdf files to markdown documents in vim. I'd create a dotted list of important copied text and then I'd like to replace the end of line hyphenation that appears ...
Paul Rougieux's user avatar
2 votes
1 answer
141 views

How can I store the number of regex matches in a variable?

In Vim Script, I want to check for the amount of matches from a regular expression (/\%^\n*) and store the amount of matches in a variable. I this possible?
Amarakon's user avatar
  • 261
5 votes
4 answers
3k views

Regex to delete all leading blank lines

Is there a Vim regex to delete all leading blank lines in the file? text more text some more text Should become: text more text some more text
Amarakon's user avatar
  • 261
1 vote
1 answer
309 views

Regex replace for equal sign in whole file

I'm trying to do a simple replace for all equal signs and subsequent characters until end of line: %s/\=.+\n/\n/. However this gives E866: (NFA regexp) Misplaced =. If I try instead to simply replace ...
Sos's user avatar
  • 113
2 votes
1 answer
53 views

Snippet lookahead trigger

Using UltiSnips, I'm wondering if it's possible to do some lookahead assertion when detecting the trigger. For example, this works: snippet "dv" "derivative" ir \dv{$1}{$2}$0 ...
Alex867's user avatar
  • 33
2 votes
1 answer
282 views

Break line after the n-th comma

Suppose I have the next line 1,0,10,10,9,7,7,5,41,3,57,7,1,9 I want to split it into several lines, each containing n commands for example, for n = 4 1,0,10,10, 9,7,7,5, 41,3,57,7, 1,9
juaninf's user avatar
  • 143
1 vote
1 answer
28 views

Replacement for ^M when scripting with Vim

I am creating a script that grabs all links from a web page's source code. I would like to call Vim from a bash script and the easiest way for me to do that is to use a vim script. I have a file ...
ex7lted's user avatar
  • 37
2 votes
1 answer
1k views

Delete all text before a specific character using vim

I have used curl to grab a website's code and put it in a text file. I'd like to delete all text that isn't a link! Lucky for me, all links are inside quotes, so I just need to delete all lines ...
ex7lted's user avatar
  • 37
0 votes
3 answers
96 views

How can I select all non-lowercase multiline blocks which follow a keyword?

I'd like to copy these to a file, but in a speculative future case, I might want to delete them. I might need to find a regex to substitute intervening data with a single blank line. The highlighting ...
Greek2me's user avatar
4 votes
1 answer
240 views

Upcase only the 3 and 4 letter words

I've written a script to convert 3 and 4 characters words, since they often are abreviations in the texts I work on. Here is the starting text : Diabetes - Hbp - Copd - I want to transform it to : ...
Vincent Willems's user avatar
1 vote
1 answer
26 views

matching with single character > or lines that start with >\s

I want to delete any lines that either match ^>$ or >\s I have something like this, but this doesn't work:nnoremap dq :.,$g/^>[\s$]/d<CR> Here's a small sample where it should delete ...
fbence's user avatar
  • 543
4 votes
1 answer
358 views

How to match the content in a pair of brackets, no matter how many pairs of brackets are contained in the content?

I want to replace GD[many[[brackets]]], GD[evenMore[[[[brackets]]]]] with GD[someStuff], GD[someOtherStuff] How can I match the correct pair of brackets? These patterns are scattered in a large ...
Yufei's user avatar
  • 41
0 votes
2 answers
66 views

How do I copy and paste the content inside quotes from one place to another?

Lets say I have a buffer with the following content: <property name="sfgiusfgsnffgdsb" value="arbitraryvalue1"/> <property name="sfsergggsnfgdfgs" value="...
andrescmasmas's user avatar
1 vote
1 answer
78 views

Vim: reformat CSS from one-line to multi-line rules

I wanted to reformat the W3.CSS file to make it more readable and study it. I looked for an easy way to do this but couldn't find it (in vim-only way, obviously, the web are plenty of solutions and ...
Antonio's user avatar
  • 187
0 votes
2 answers
37 views

Neovim wont match beginning of word with # sign

/\< matches beginning of all words as expected. /\<a matches beginning of all words starting with a but /\<# doesn't match words starting with # what am I missing here? Was planning on using ...
Jordan Mandel's user avatar
0 votes
1 answer
109 views

vi regex no match

I have this os.environ.get("DB_NAME") and I am trying to use the vi regex command % s/os\.environ\.get\("DB_NAME"\)/db_name/gc to match that. I used it to change flaskdb to os....
George Udosen's user avatar
2 votes
3 answers
270 views

Capitalize a match in search and replace

I am using the following regex to find the first letter of the last word on each line in a file: %s/.* .\zs/ I want to now lower case this match on every line in a file. How do I do it? For eg. Before:...
user81371's user avatar
0 votes
1 answer
73 views

How to join multiple lines which doesn't include space at the end

I'm working on a subtitle document (.srt) which has thousand of lines. But this issue is not about the subtitle documents, I going to export as plain text to read after. To see the dialogs line by ...
Pascowl's user avatar
3 votes
0 answers
139 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
1 vote
1 answer
339 views

How can I remove duplicates in comma-separated text, ignoring the first column, keeping only unique lines?

I have a sparse CSV file with data shaped like in this simplified example. I am omitting the header, Age,Fruit,Color,Count, but I can include it in my file if needed. You can see that the sparse rows ...
Kevin Duggan's user avatar
1 vote
0 answers
17 views

Search and replace with regex in the replacement [duplicate]

I would like to replace all instances of match("something") with match("something", source). However, using :%s/match(.*)/match(.*,\ source)/g replaces it by match(.*, source). ...
sadfasdfasdfddd's user avatar
1 vote
1 answer
53 views

"non-greedy" [<any chars>](word) regexp problem

consider this sentence (a line in a text file): mi chiamo [Giorgio Robino](person) ed abito in [corso Magenta 35/4 a Genova](address) I want to search (select/extract) the pattern <any chars> ...
Giorgio Robino's user avatar
-2 votes
1 answer
28 views

I want to get the Use% values from this individually. I used \d+% to get the values having %

I would like to match percentage in the next lines: Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 1503280 1388392 20476 99% / /dev/mmcblk0p7 2753568 4616 2586036 1% /var/lib/docker /...
pranjal gupta's user avatar
1 vote
2 answers
77 views

How to make substituition of pattern if it occurs after different pattern?

I would like to have a regular expression that replace: "foo" "bar" Is "hello" "world" "!" by: "foo" "bar" Is "hello world !&...
Vivian De Smedt's user avatar
2 votes
1 answer
202 views

How to select a regexp group in vim?

I want to select/visualize a regexp GROUP in a vim regexp expression in vim. By example I would like to highlight (search) a span of characters inside square brackets, having this line: bla bla bla [...
Giorgio Robino's user avatar
1 vote
1 answer
145 views

Ultisnips not working with space

I have the following snippet context "math()" snippet `v([a-zA-Z]) ` "bb" A ``rv = '\\mathbf{' + m[1] + '}'`` endsnippet Now, most of my snippets work, however, snippets with ...
Maths Wizzard's user avatar
1 vote
1 answer
135 views

How do I use the \+ quantifier?

Running Windows 10 (Home) and VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:36:07) MS-Windows 32-bit GUI version with OLE support Included patches: 1 Compiled by mool@tororo. I have ...
query-01's user avatar

1
2 3 4 5
11