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
1
vote
2answers
145 views

Trying to undestand why using \zs in regex is not working as I expect

Consider the following test String: County,Age,Age_group,Gender,Jurisdiction,Travel_related,Origin,EDvisit,Hospitalized,Died,Case_,Contact,Case1,EventDate,ChartDate,ObjectId If use the following ...
0
votes
2answers
69 views

How do you :tag: every word of a line using substitution?

How do you substitute every word of a line, so that it becomes a useful vimwiki tag? Provided the following line: Word Compund_Word I want: :Word: :Compund_Word: I guess it involves some use of ...
1
vote
1answer
24 views

Is there a function which returns the filepath at the cursor?

I'm looking for a function(probably doesn't exist) which can return the filepath under the cursor. I know that there is a command/shortcut gf that helps me jump to that file if the file exists. But I ...
1
vote
2answers
93 views

Remove a pair of brackets without using plugins [duplicate]

I am looking for a way to remove a pair of brackets in the insertion mode without plugins. It's like (|) When I press the delete key only the first bracket get deleted |) But I want to auto-remove ...
1
vote
3answers
88 views

Convert sed regex to vim regex

I got this sed regex I found: sed '/start/!d;s//&\n/;s/.*\n//;:a;/end/bb;$!{n;ba};:b;s//\n&/;P;D' which basically outputs the content that is between a starting point and an end point. ##1## ...
1
vote
1answer
46 views

Pipe :Ag output to a new buffer

I'd like to search for a regex using Ag. This results in more than 1000 findings. I'd like to save these findings in a buffer to be able to go through them slowly
1
vote
2answers
49 views

Vim equivalent to Perl regex for making a substitution in a substitution?

I have this perl regex: s/(^(#+)\s.*?\g2)/$1 =~ s|\n| |rg/gmse It strips out all new lines between ##+ characters and replaces them with a space. It'll take a string like: before text more text ### ...
3
votes
2answers
153 views

Can't repeat negated pattern using \@!

I have this text: ```python x = 1 ``` Basically markdown python cells. I would like to extract the content of the cell surrounding the cursor, if any. As you may have guessed already, I am trying to ...
1
vote
1answer
18 views

Unable to execute a substitute regex from inside a function

I have this function: function! Insert_article() execute "normal! :r !insert_article.pl\<cr>" execute "normal! :%s/\v^(#+\s+[^\n#]+)\n([^#]*#+)/\1 \2/g\<cr>" ...
1
vote
1answer
24 views

Why does match whole word not working in conjuction with regular expressions?

I am trying to use regular expressions to find common-markdown elements (I am new to vim & regular expressions). For example to find a strike-through ~~something~~ I am searching for the following:...
4
votes
1answer
110 views

what is `\_^` (backslash underscore caret) for in Vim?

From :help ordinary-atom: ordinary atom ~ magic nomagic matches ~ |/^| ^ ^ start-of-line (at start of pattern) |/zero-width| |/\^| \^ \^ literal '^' |/\_^| \_^ \_^ start-of-...
2
votes
1answer
85 views

How can I find where one word is close to another word?

If I want to find occurrences of the word 'arc', I can type / arc , with spaces around the three letters, to find basic occurrences of the word (ignoring punctuation). But suppose I want to find where ...
0
votes
2answers
59 views

Define a new ex command active only in specific filetype (C++)

I would like to define a new command for C++ files/buffers (ft=cpp). I shall explain the requirements through the example below. The newly defined command :stripdbg should strip the surrounding dbg() ...
1
vote
2answers
61 views

How to create regex group with dependency with earlier group via math operations

Imagine I have a file as follows, 10 10 10 11 ... 10 20 20 20 20 21 ... 20 40 40 40 40 41 ... I know simple regex such as To search two numbers /\d\+ \d\+ To search repeated numbers /\(\d\+\) \1 My ...
0
votes
0answers
12 views

Paste into search instead to buffer with vim-fuzzyseach?

I’m using this plugin and find it useful with its regrex search and as it’s not updated recently, I find that when I map it to / to replace default function search of vim and then try to paste text ...
1
vote
1answer
10 views

Passing a pattern as argument without extra escaping

so I want to pass a pattern to a command. command! -nargs=1 -buffer Vim silent exec "vim! /" . <args> . "/ ./*" | copen | redraw! But there is a problem. If I want to match /foo i would use ...
2
votes
2answers
42 views

How to exclude a pattern between a pair of parentheses?

I have the following Python code z=xyz%10 gvu.set_ticks(ax, xticks=[45, 50], yticks=[-25, -20, -15]) After this substitution, in visual mode :s/\([^=]\)\ *\(=\)\ *\([^=]\)/\1 \2 \3/g ...
0
votes
1answer
32 views

global search and replace on all lines that don't begin with a backslash

I'm trying to globally enclose in {}'s all instances of +,-,= that aren't already so enclosed. But I don't want to do this for lines that are latex commands. Since my latex commands are all on ...
1
vote
1answer
24 views

Regex for matching the argument of a tex macro

Using the regex \\todo{.\{-}} I am able to match \todo{stuff} But what I want to match is {stuff} whenever \todo immediately precedes it. Basically I do not want to include \todo in the matched part. ...
1
vote
1answer
24 views

How to insert text using substitute and regex?

Honestly I can't read regex for now. I have quick-fix list and I have a hunch that this can be done with regex but I don't know how. I want this: @ViewChild(MatTable) @ViewChild('text 1') @...
-1
votes
1answer
25 views

Regular expression find and replace

Trying to use regex 25, s/\(Test.assert_equals(\)\(pick_peaks([.*\])\)\(.*\)/print("\2")/g to replace the lines below with print(pick_peaks(...)) My find pattern seems to be working as in vim the ...
1
vote
1answer
46 views

exclude character classes inside [] in a regex

I want to write a regex that finds words contained in brackets, like [word]. The words are not allowed to contain spaces or the characters [ or ]. I tried with \[[^\[\]\s]\+] But applied to the ...
1
vote
1answer
24 views

Continuous number substitution

Suppose you have a textfile: Time step #1 (t = 0 a.u. = 0 fs) unneccessary text unneccessary text unneccessary text ... Time step #2 (t = 10 a.u. = 0.24189 fs) ... Time step #3 (t = 20 a.u. = 0.48378 ...
0
votes
1answer
27 views

Given a set of patterns, list (in the quickfix window) the ocurrences in those files that contain all the patterns from a given directory

The context Given a {pattern}, I can list the ocurrences of {pattern} in all files from a {directory}, in the quickfix window with the following command :chdir {directory} :vimgrep /{pattern}/ **/* :...
0
votes
1answer
20 views

Improve regex for SQL highlighting

I have the following regex to stylize SQL keywords within a string (keywords shortened for readability): autocmd Syntax * syn match pythonSql /\v("|')\s*([A-Z]{3,}<.*)@=\zs(SELECT|FROM|WHERE) ...
0
votes
0answers
16 views

Stylizing a string that contains a regular expression

In textmate (and I assume every other editor), it has a nice feature where it colorizes a regular expression inside a string (r-string in python). For example here is how it looks in Texmate: Is ...
0
votes
1answer
16 views

How to properly escape a string in a vimrc file

I am trying to add in a regex that matches either: u'...' or: u"..." To highlight the u before the string (it's a python thing). This is what I have so far: autocmd Syntax python syn match ...
1
vote
3answers
106 views

How to delete everything except urls?

I have string like this: 1668955,,, bunch of text</figcaption><br /><a href="https://the_url/article_detail.php?article_id=10003414" target="_blank">w..... </a><br />&...
2
votes
1answer
73 views

Create a mapping in .vimrc that accepts an argument

I want to create a mapping in my .vimrc file that takes an argument. I'm constantly defining latex commands which require arguments inside of curly brackets and writing them instead inside regular ...
2
votes
1answer
187 views

How to match this syntax group?

I'm trying to improve on the MySQL syntax highlighting, for my particular code base. I have a lot of this sort of thing FROM TBL_ENTITIES E JOIN TBL_RELATED_ENTITIES RE ON RE.entityFK = E....
2
votes
0answers
18 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 ...
2
votes
3answers
383 views

How to run multiple commands in command line, & place 1 comma at the end of each line and join all the lines

I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1. I'm having a problem with the following command in the NeoVim command line: 1 ...
2
votes
1answer
80 views

What exactly does \%(…\) and \z(…\) do?

I know \(...\) is Vim's way to create a capturing group. It was listed under the atom entry in Vim's doc. There are two other forms of atom, \%(...\) and \z(...\). The document is not very clear on ...
0
votes
1answer
26 views

Is the pattern .\{-}\> equivalent to the move command e?

What is the appropriate way to make a pattern that matches up until the point where the move command e would have moved to? Consider this text: texttext%0s: cookie after performing /%<CR>ve the ...
2
votes
1answer
27 views

Gathering groups (only) in regex [duplicate]

I've come across regex substitutions in vim, but was wondering if there was more the concept of something like regex.group() in vim. For example, from the site "VimGolf", here is one example input: ...
1
vote
1answer
48 views

Empty space between two &

I want to empty inner columns in a latex table, ie all the words between 2 &. How I can do it ? I have tried quite a few formulas like s/&*&/\& \&/gc but I just can't find ...
2
votes
2answers
35 views

Regex flavor in vim for doing substitutions

I'm having a hard time writing regexes in vim -- it seems everything I try either requires an escape character or isn't supported. For example, I have a SQL statement that includes something like: ...
0
votes
1answer
50 views

gvim editor — E488 Trailing characters after search and replace questions

I have the following search and replace expression where I am trying to format a document in a single step using multiple commands separated by | :%s/\s\{6}...\d\d\s/ /g | %s/\(.*Inlet.*\|.*AIR.*\)/\...
1
vote
1answer
88 views

Add decimal mark to each number of each line

I have an R file of results, such as below: filename run1 run2 run3 file1.py 109 103 100 file2.py 14123 14323 14333 ... filen.py 2007 2130 2001 What is the easiest way to use VIM for adding ...
3
votes
1answer
52 views

How to match paragraphs of text ending with a character?

This problem that seems trivial is beating me real hard. I'm trying to create a couple of syntax highlighting directives for a custom language that is structured in paragraphs separated by at least ...
0
votes
1answer
11 views

How to find and replace a group while keeping the word

How using vim serach and replace change title: <Translation {...messages.title} />, title: <Translation {...messages.header} />, title: <Translation {...messages.message} />, into ...
0
votes
1answer
19 views

delete every line which has double entries with a regex

I have a bunch of csv files which look sort of like this: date,receiver,client,article_id,amount 5-12-2019,thomas,thomas,2,23 5-12-2019,joe,joe,2,14 6-12-2019,tobias,bob,4,1 now I would like to ...
1
vote
2answers
95 views

Match and highlight urls

I'm trying to make it so urls are highlighted and a shortcut can be used when the cursor is on top of one to open it in browser. Added this to a syntax file: syn match matchURL '/http[s]\?:\/\/[[:...
-1
votes
2answers
54 views

How to replace spaces inside a selection

I have this text : He's a self made man who gets what he wants. The small blue forget me not flower was first used by the Grand Lodge. And this function: function MyFunction() let myList1 ...
0
votes
2answers
71 views

Searching between two words

I have this string : content htp://ww.mySite.com/image/123kw9ykjm-065n/640/568/25452583.suite />meta property="twitter:suite and I want to get the link to add it in a list; Here is my function : ...
1
vote
2answers
123 views

Regex missing matching words

I am trying to add some custom highlighting to my Vim. But my regex matching is not working correctly. let ignoreHiInComments = '^\s*\(\/\/.*\)\@<!' "Ignore highlighting in C++ comments call ...
0
votes
1answer
28 views

Changing multiple columns of all lines that meet a search criterion

There are lots of posts about how to search and replace a single column of a file, using \%Nc syntax. I want extend this syntax to replace multiple columns in all lines that meet some criterion. For ...
1
vote
1answer
74 views

Search for Pattern “^M*”

My file contains multiple blocks looking like this some Test "^M ^M ^M "some more text I'd like to remove these passages (including the "), but can't seem to fine the right regex. EDIT: I already ...
1
vote
1answer
68 views

How do I add a thousand seperator to a number?

Is it possible to add a thousands separator to a number or a selection of numbers? Before 42 4815162342 After 42 4.815.162.342 I have to perform this operation quite often, which is why I would ...
1
vote
2answers
64 views

Trouble Splitting a YAML-Like List

I'm working on a plugin that needs to parse a YAML-like list and I can't quite nail the pattern needed to split the string. The pattern needs to match a comma delimited list that can have both singly ...

1
2 3 4 5
9