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
1answer
54 views

Regex for all spaces that not surrounded by quotes

I'm trying to write a regex that matches all spaces except those enclosed in quotes. I found solutions on the Internet for various programming languages, for example, here, but I am having trouble ...
2
votes
1answer
41 views

What is the difference between character classes \d and [:digit:] in a regular expression?

I studied a tutorial for vim syntax files and found this example: " Floating point like number with E and no decimal point (+,-) syn match celNumber '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+' I was ...
1
vote
1answer
12 views

Why did \a match some non alphabetic characters

As my understanding, in the regex of Vim, \a matches any of alphabetic character. Now I'm trying to change the line file_exts = [tex, log, aux,] into file_exts = [(tex), (log), (aux),] I've tried to ...
0
votes
0answers
19 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-...
0
votes
0answers
27 views

Insert newline (\n) at search and replace but get “^@” instead [duplicate]

I want to set a linebreak after all braces }. I tried to replace the braces by newline \n with: :%s/\}/\n/ But all I got is a ^@ instead of a new line. Example: abc{def} foo bar{baz} and so on I ...
0
votes
1answer
19 views

Using “(?=<)” in regex leads to “E866: (NFA regexp) Misplaced ?”

The following command should output the string "st": :echo matchstr('test', '\(\?<=e\).*') However, it leads to the error mentioned in the title. Reading :h E866 didn't help much. I also ...
1
vote
1answer
24 views

replace simple pattern with sequential next line from another file

My file working.txt has 1000's of lines, which repeat in a simple pattern as follows: name date_ax name date_cd name date_ed name date_dc ...etc I need to replace each instance of name with the ...
2
votes
1answer
59 views

Moving by word (w/b) and staying within the line

Background I'm attempting to remap the arrow keys to move by word while staying within the current line. I.e. I'm looking for a behavior similar to w and b, but that acts like h and l in the sense ...
0
votes
1answer
23 views

How to create an abbreviation that matches a regular expression

I'd like to create an abbreviation that will change the following (in a markdown file): - list item 1 into this: - list item 1 Whenever I type - f it should be expanded to - f (from 1 space to 3 ...
0
votes
1answer
23 views

How to put sync region start=<this> into a variable?

I have the following code: com! -nargs=* ShFoldFunctions <args> fold ShFoldFunctions syn region shFunctionOne start="^\s*[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\s*()\_s*{" end="}&...
1
vote
1answer
30 views

How do I do substitution against just part of a larger pattern?

I have a string like 18NTC101L , which I can search by \v[0-9]{2}[A-Z]{3}[0-9]{3}L. Now, I just want to replace the L at the end with letter T. How I can do that?
1
vote
1answer
83 views

Insert and remove a marker at the start of the current line

So, I'm trying to set up a sort of bookmark/marker kind of workflow, and I came to notice I'm used to put characters such as # and such for different meaning inside my own notes, etc. Now, I already ...
0
votes
1answer
25 views

Add or remove single quotes around numbers in yaml files with vim [duplicate]

I'm editing some large YAML files with neovim, and need to add (and remove, in some cases) single quotes around some values. For example - code: 1234 needs to be changed to code: '1234' in other cases,...
1
vote
1answer
35 views

Why does /^[\s]* not work how I expect?

I use vim as my $MANPAGER. I will often use :/^[ ]*-F (for example) to quickly jump to a flag and read up on it. However, the equivalent :/^[\s]*-F doesn't return the same results. Why not?
5
votes
0answers
57 views

Matching any Unicode whitespace

I'd like to match in Vim any whitespace character, not only normal space (U+0020) and tab (U+0009) with \s, and the other ASCII ones like form feed (U+000C) with [[:space:]], but any Unicode ...
0
votes
1answer
25 views

Can't replace div using regex

I have the following code from lines 6-20 <div> 1 </div> <div> 2 </div> <div> ...
1
vote
0answers
62 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 ...
2
votes
1answer
38 views

Caret `^` and `\%V` compatibility in Vim regex

Can the caret ^ and the sequence \%V be used to match the beginning of a line in a visual selection? And if not, what is the rationale? The following example seems to indicate that ^ and \%V are not ...
3
votes
2answers
108 views

Is it possible to close all files with content that matches a regular expression on Vim?

Let's say I have opened many files on Vim with vim file1 file2 file3... And their content is like the following: file1: random content random content stringThatMatchesRegex random content file2: ...
1
vote
2answers
290 views

How to match all C code comments in a file?

I want to match (search) all C code comments in a file in e.g. enum { foo, /* Foo is so cool, why can't we all be more like foo? */ bar, /* but bar is mysterious and ...
0
votes
2answers
30 views

How to replace a sequence of multiple words in multiple lines with a condition of another word in the same line?

I need your kind help on writing a regular expression for the following situation. Consider the following first word sequence: Criteria A xxx xxx xxx Table1 Criteria A xxx xxx xxx Table2 Criteria A ...
0
votes
0answers
27 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?
0
votes
0answers
42 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 ...
0
votes
1answer
22 views

Regex macro to remove only lines NOT containing specific content

Given a word list, I would like to delete all lines that do not have a specific content. For illustration, In the following list, I would like to delete all lines that do not end in s. bird chairs ...
2
votes
2answers
103 views

Is there a way to use matchadd() to highlight multiple lines without highlighting newlines?

Suppose I have this in a text buffer (vim --clean mydoc.txt): One Two Three Four I highlight all lines using :call matchadd('ErrorMsg', '.*'), resulting in: Notice that the newline character on each ...
1
vote
2answers
90 views

Copy to clipboard or save to file substitution command

I'm trying to answer a vim question in U&L, which involves a very complex and long regex substitution. I would like to copy to clipboard the command, or save it in a file, so I don't have to make ...
0
votes
1answer
51 views

Language specific custom syntax highlighting

So I have to follow a name convention for my C data types : Typedefs must start with a t_ prefix such a t_mytype. Structs must start with a with an s_ prefix and so on for other data types. So I added ...
1
vote
1answer
31 views

How to match brackets in matchadd command regular expression?

I want to highlight breakpoint() - including brackets as keywords in Python files. I have added these two commands to my .vimrc: highlight link PyBreakpoint Keyword call matchadd("...
3
votes
1answer
144 views

Why don't these multiline regular expressions using a positive lookbehind work?

EDIT: Don't waste time reading this question unless you're interested in a good example of why you should always check the :help first: a severe case of PEBKAC. Consider the text: foo . . barbaz ...
-1
votes
1answer
12 views

Automate joining lines in text blocks (perhaps with SHIFT+j) but do not join blocks [duplicate]

I have the lastest versions of arch and nvim which I am using. I have a text that looks like this the slow brown fox jumped over a bridge the blind brown fox stumbled upon a badger ...
0
votes
2answers
48 views

Append a line after matched multiline pattern

i want to run this global command : /3)\(.*\n\?.*\)\{1,10\};;/ which matches multlines. I want to append a line after the matched block(of lines) across multiple buffers. I don't know where to begin ...
0
votes
2answers
57 views

How do I ignore specific words in a search and replace regex?

I am using this working regex :%s/\( to\)\([a-z]\)/\1 \2/c to replace tothem with to them and tohim with to him. But I do not want to look at words like together, tone, tonal, etc I tried something ...
0
votes
0answers
36 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 ...
1
vote
1answer
30 views

User <cword> inside a vimgrep regex expression

Writing a map to find header under cursor for markdown link. ## heading {#foo} ... ... [click on link](#foo) <- `cursur above this foo` What I am doing: nnoremap gO :lvimgrep "\v^#+.*(#.*)&...
3
votes
1answer
207 views

Join multiple lines based on pattern

I have text bounded by quotes as follows "This is an example of some text" I want to join these into one line. e.g. "This is an example of some text" I have tried commands like ...
1
vote
1answer
27 views

Can you call highlight more than once? Need different colors for different matches

I am working with text files and Goyo. I'd like to highlight two different kinds of notes delimited by brackets (one called "NOTE:" and the other "TODO:") in different colors. I ...
0
votes
0answers
51 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 ...
2
votes
0answers
19 views

Vim replace repeating pattern [duplicate]

I got this repeating pattern, but when trying to replace it in vim like: %s/<pat>\_.*<\/pat>// It will replace from first to the very last . How to replace these pattern by pattern? My ...
1
vote
1answer
14 views

\s doesn't work in matchstr

I have this in my init.vim: autocmd TextChangedI <buffer> echom matchstr(getline(line('.')), "^\s*y") I was expecting to get the first part of the line if I enter something like that: ...
0
votes
2answers
43 views

Test string after a pattern

I want to test, if the cursor is currently in a comment line. For example in C it looks like this: // This is a comment line now it's also possible that it's a big comment section: /* * Big comment ...
2
votes
1answer
41 views

Convert working commands to VIMRC friendly mappings (ie: :%s with regex)

Is there a simple way of taking a previously issued command and converting it into a .vimrc-friendly keybinding? For example, I have a simple substitution utilizing regular expressions that won't work ...
1
vote
1answer
19 views

Why does this pattern make :global work only on the first line of the highligted match?

\/\*.*\(\n\s\*.*\)*\n\s\*\/ is a pattern which I cooked up to match some multi-line C comments, i.e., in the format of: /* Comment Text * Comment Text * Comment Text */ Searching for the pattern ...
1
vote
2answers
289 views

Replace regex group in nvim

I'm using the most recent version of nvim on arch. I have sentences in my text like this The brown fox I wish to use this format :%s///g to replace all lines starting \nlowercase letter + rest of ...
1
vote
1answer
1k views

How to regex match beginning and end of a file?

Using /, I want to be able to search for (and jump to) the beginning and end of the file I am in.
2
votes
2answers
514 views

Regular expression for searching IP addresses

I opened up a document in vim and I want to search the document for IP addresses. So I used this command /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} But this pattern doesn't seem to return any of ...
0
votes
2answers
29 views

append things to the end of a pattern

I have several instances of variables in a file and I need to modify the variable and append "new" to each of the names. var Modelfrfr = .... var Modeldede = ... var Modelenen = ... ...
2
votes
1answer
97 views

why doesn't regex work in vimscript (while it does in normal search)?

I have simple regex to search for lines that only contain alphabetic characters: ^\(\a\)\{1,}$ which works in normal search /^\(\a\)\{1,}$ but not when invoked from my script: "in .vimrc file: ...
1
vote
1answer
25 views

How to replace [ with ( in vim

I have this markdown line, ![Home][screenshots/home.png] I want to replace it with, ![Home](screenshots/home.png) So, I tried this, :%s/[s/(s/g Vim(version 81) says pattern not found.
1
vote
1answer
46 views

How to recursively open all files except ones in hidden directories from within vim?

In my python project root folder, there are multiple directories, some of which contain hidden sub-directories specifying python virtual environments. I want to open all my python files recursively ...
2
votes
0answers
59 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}, ...

1
2 3 4 5
10