Questions tagged [regular-expression]

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

18 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
17
votes
0answers
418 views

How does `\zs` interact with syntax matches?

Consider the text: foobarbaz First we highlight the regular expression /foobar/: :syntax match Special /foobar/ Next we highlight the regular expression /foobarbaz/: :syntax match Error /...
3
votes
0answers
464 views

Highlight python raw strings as regular expression

I heard someone had set up their editor to highlight python raw strings as regular expressions, e.g. for Django: urls(r'^site1/(\d)*/new$'', ...) Unfortunately my googleing doesn't get me anything. ...
2
votes
0answers
32 views

Substitute regex group in prompt when replace with confirmation

I am using vim to replace with simple regex: %s/Foo\(.\)/Bar\1Biz/gc I wanna to confirm each occurence and Vim asks: replace with Bar\1Biz (y/n/a/q/l/^E/^Y)? Is it possible to substitute group (\1) ...
2
votes
0answers
161 views

How to match patern inside a syntax region start pattern?

Python group regexp has this syntax (?P<idGroup> ... ), where: (?P<idGroup> is the beginning of a region. ... is the content of the region. ) is the end of region. I highlight start ...
1
vote
0answers
60 views

custom fold expression to fold functions

I would like to create a custom fold expression for functions of the form x <- function(a,b,c) { ... ... body ... } where the lines starting from function(...) until the closing brace are ...
1
vote
0answers
31 views

search and replace: remember case in substitute

I have to change strings: fetchrandomData to fetchReportingData FETCH_RANDOM_DATA to FETCH_REPORTING_DATA I can change ca_z and CA_Z to ca_t and CA_T respectively with command: %s/\v([Cc])([Az])(_)?...
1
vote
0answers
39 views

How to specify Perl encoding in Vim?

For a buffer containing text "กขค" with UTF-8 encoding: :perldo s/ข/x/g => "กxค" but :perldo s/[ข]/x/g => "xx�xxxxx�". How to specify Perl's encoding? Note: Currently I have to use %:!perl -C -...
1
vote
0answers
24 views

Syntax - Match word based on a previous match

I want to highlight all words that have been matched in another syntax region. Using something similar to regex capture groups, for example given a file: {highlightme} asda asasd asd asd as ...
1
vote
0answers
60 views

Disable regex searching in specific windows

I usually have about 4 or 5 windows open in Vim. Currently - one of my files is very large(in size) - a CPU cache trace. Every time I search with "/", vim searches all windows before returning the ...
1
vote
0answers
34 views

How to access syntax elements

I try to inline one syntax in another syntax (to be explicit: CSS in JS template strings). I'd like to build on top of the existing CSS definitions and not create new ones. Question: Is it possible ...
0
votes
1answer
30 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. ...
0
votes
0answers
37 views

Regex match inside XML container

I'm trying to match data in a gnucash record, without skipping into the next record, so basically needing to stop matching at the closing tag. The record looks thus, for example: <trn:split> ...
0
votes
0answers
55 views

can not make this regex pattern work in “very magic” mode

I am trying to construct a regex pattern to match characters inside two # characters. For example: #abc#bc#cd# I would like to match abc, bc and cd. The following regex without using magic mode ...
0
votes
0answers
37 views

Regex to remove newline; works in one vim instance, but not another

Trying to remove newlines with a regular expression (not shift-j). I have one vim install where :g/conf/s/\n// works as intended, removing a newline from all lines containing 'conf'. I have a ...
0
votes
0answers
30 views

Search and replace any number separated by : trailing with number or alphabet separated by . and / or - or _

Search pattern examples "0:4.10.5-5.el7" "0:0.7.7-13.20120626.ov7" "6:4.14.8-6.po7_3" How to search and print all occurrences like above patterns where the first number can be any number ranging ...
0
votes
0answers
33 views

How to pass '\v\C[pattern]' into the built-in match() VimScript function

I am attempting custom fold logic as my first VimScript. What works for me: USING VERY MAGIC (\v) and explicit CASE SENSITIVE (\C), find python comments in foo.py that begin with hash, then Roman ...
0
votes
0answers
138 views

Match everything except some characters and some strings?

I want to non-greedily match a string that don't contain ,, :, 。and #c, and I have tried this: ((,|。|,|:|#c)@!){-} which doesn't work. How can I make it work?
0
votes
0answers
264 views

Matchit Plugin: issues when resetting regular expressions in “b:match_words” for detecting Matlab file keywords

I'm trying to implement a custom regexp string to be used by matchit.vim for identifying matching keywords that can be jumped between with %. I found a utility from FileExchange (in the ftplugin ...