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
1answer
19 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
22 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
21 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}/ **/* :...
-1
votes
0answers
17 views

Comparing two regex in vim with word boundaries

Why does this regex match: /\v("""|'''|"|')\s*[A-Z]{3,}\w But using the \< word boundary instead of \w does not (I've tried it with/without escapes/magic modes and none of them match):
0
votes
1answer
16 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
14 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
94 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
48 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
79 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
17 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
322 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
69 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
23 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
23 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
23 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
36 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
53 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
49 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
73 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
53 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
61 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
56 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
34 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
27 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
89 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
97 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 ...
2
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
51 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 ...
5
votes
2answers
588 views

How to highlight matching string while typing a regular expression?

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
42 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 ...
2
votes
2answers
252 views

How to use lookahead and lookbehind in vim in the same line

I am trying to delete all the spaces that aren't sandwiched by a letter. So this I am trying; but ; I can't find a way ; should be this I am trying;but;I can't find a way; I tried this but it ...
1
vote
2answers
212 views

How to replace a space with a colon - command line mode

Input Every line is separated into 8 parts by semicolons Every part can include words,numbers,space etc. Output I am trying to replace the space in the 6th part with a semicolon, thus separating ...
7
votes
6answers
2k views

How to replace a pair of brackets

I have a file, containing some lines like this: aaa bbb (ccc) ddd. Now I want to replace the pair of brackets by a pair of square brackets to make this line become aaa bbb [ccc] ddd. I think that \...
1
vote
1answer
191 views

How to paste text after each line matching a pattern?

I have a file like this: int var; int f() { // Use of var } int g() { // Use of var } int h() { // Use of var } // ... I want to move my global var into each function to get this ...
1
vote
1answer
62 views

How to match a word not following a defined pattern?

I have the following text file: 1: This is a book. 2: Here is the book for you. 3: There are book. 4: You can read the book. 5: Is book good to read? I want to find all occurrences of book not ...
1
vote
1answer
140 views

Adding prefix and postfix to matching regular expression

Dear fellow Developers, I would like to quote variables having @ inside like test@mail.org, but not starting with @ like @var1, @var2. Does Vi/Vim/Neovim have any option to inspect the matched pattern ...
3
votes
2answers
203 views

Replace after a specific pattern

Suppose I have a string as follows: RESULT=100 How would I replace everything following 'RESULT=' so that the string reads: RESULT=200 The closest I've gotten so far is to use: :%s/\(RESULT=.*\)\@...

1
2 3 4 5
8