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
32 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
10 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
40 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
28 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
17 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
24 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
23 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
23 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
26 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
18 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
15 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
13 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
100 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
61 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
108 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
337 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
71 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
24 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
26 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
31 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
29 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
86 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
39 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
65 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
52 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
50 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
87 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
27 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
54 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
64 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
59 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 ...
0
votes
1answer
37 views

syntax match: redundant end of line marker “$”

I am looking to create a new syntax. This is what I have so far: syntax match jl_comment "^# .*" but I have noticed other examples using pattern like this: "^# .*$" Example: https://github.com/...
4
votes
0answers
28 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 ...
0
votes
1answer
90 views

search a pattern preceding cursor position, modify it and insert the modified string

I am writing a mapping to autocomplete tags Pattern: <.*?>, matches complete HTML tags only. The goal is to lookbehind and see if there exists a text like <html>. Mapping: inoremap <...
0
votes
0answers
20 views

Select first char up to first non camelCase or non upper case char or up to first snake case _ in vim [duplicate]

I used this map: map ,w v/\([^ a-z]*\|[^ A-Z]*\)<cr>h the idea is to select in the words mysuperTest MYSUPER_TEST mysuper_test I want to be able to select 'test' and 'mysuper' depending if ...
1
vote
1answer
17 views

How to match as many as possible in group?

I have a question about vim regexp, How can I match as many as possible in a iterm group? ther string is op test or op test or optest, I want to match test, my expr is \(op\s*\)\@<=[^ ]*, but ...
2
votes
2answers
38 views

How to search and replace more than character and a string in vim

I know it should be easy, but somehow I don’t get it right. I've got a text with artist_id, album_id,... and want to replace them with just id. How do I do that? I tried :%s/[a-z]+_id/id/gc, but ...
1
vote
2answers
100 views

Why does matchlist() return empty strings at the end of the result?

From the Vim's help: echo matchlist('acd', '\v(a)?(b)?(c)?(.*)') Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] I understand why the 3rd element is an empty string: 'b' is not present in ...
4
votes
2answers
1k views

Grabbing values between quotation marks

I want to create a regex that matches strings within single or double quotes in vim and that considers the fact that some strings might have escaped single quotes or double quotes. So far, I've found ...
1
vote
1answer
44 views

How to add a certain word before the names of methods in Javascript?

I am working with react. First I had a component with state I created methods and all that. Now I want to convert it into stateless component. I have add the word function before each method name. ...
4
votes
1answer
56 views

search & replace: how to add a line feed to break up a line?

So, I have the following line where I would like to find all the {#}= and put them on a new line. Of course there can be more then 9 value entries and there is more text on the line, so I am thinking ...
6
votes
2answers
676 views

Enable incremental search and highlight while typing a search term?

While I enter a regular expression on the vim command line, I would like to see what matches the partial expression I already wrote. For example, while writing the command :%s/regular all words ...
1
vote
1answer
53 views

How to execute with call and <C-R>/ matching?

I want to count the searching pattern and here is my code: execute '%s/' <C-R>/ '/\=' . Count(submatch(0)) . '/gn' Here is my Count function: function! Count(match) if has_key(b:types, a:...
2
votes
2answers
38 views

Why do the \| characters in an :execute “normal …” mapping require extra escaping backslashes?

I'm struggling to understand a character escaping situation involving \|. First I'm running the following search which matches either the A character or B character. I'm using the default magic ...

1
2 3 4 5
8