Quite confused about `?` in vim's regex [duplicate]
This question already has an answer here:
How can I make my match non greedy in vim?
8 answers
I'we been trying to do simple substitution in vim, and find out that the ?
in vim not works with *
or +
, saying that (NFA regexp) Can't have a multi follow a multi
, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^(.*?)here//
If I remove ?
it works, but the it regex matches up to 2nd here
.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use ?
with *
or +
in vim?
regex vim
marked as duplicate by mercator, Community♦ Jan 19 at 11:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I make my match non greedy in vim?
8 answers
I'we been trying to do simple substitution in vim, and find out that the ?
in vim not works with *
or +
, saying that (NFA regexp) Can't have a multi follow a multi
, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^(.*?)here//
If I remove ?
it works, but the it regex matches up to 2nd here
.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use ?
with *
or +
in vim?
regex vim
marked as duplicate by mercator, Community♦ Jan 19 at 11:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I make my match non greedy in vim?
8 answers
I'we been trying to do simple substitution in vim, and find out that the ?
in vim not works with *
or +
, saying that (NFA regexp) Can't have a multi follow a multi
, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^(.*?)here//
If I remove ?
it works, but the it regex matches up to 2nd here
.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use ?
with *
or +
in vim?
regex vim
This question already has an answer here:
How can I make my match non greedy in vim?
8 answers
I'we been trying to do simple substitution in vim, and find out that the ?
in vim not works with *
or +
, saying that (NFA regexp) Can't have a multi follow a multi
, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^(.*?)here//
If I remove ?
it works, but the it regex matches up to 2nd here
.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use ?
with *
or +
in vim?
This question already has an answer here:
How can I make my match non greedy in vim?
8 answers
regex vim
regex vim
edited Jan 19 at 9:36
BladeMight
asked Jan 19 at 9:25
BladeMightBladeMight
1,4351225
1,4351225
marked as duplicate by mercator, Community♦ Jan 19 at 11:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by mercator, Community♦ Jan 19 at 11:39
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
As stated there, you can't add the ?
char in vim after the asterix.
To make the search non greedy, you need to use .{-}
instead of .*
:
:%s/(.{-})here//
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
add a comment |
Another option is to use negative lookahead:
:%s/v^((here)@!.)* here//
v
is used for very magic to avoid escaping all over in regex.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As stated there, you can't add the ?
char in vim after the asterix.
To make the search non greedy, you need to use .{-}
instead of .*
:
:%s/(.{-})here//
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
add a comment |
As stated there, you can't add the ?
char in vim after the asterix.
To make the search non greedy, you need to use .{-}
instead of .*
:
:%s/(.{-})here//
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
add a comment |
As stated there, you can't add the ?
char in vim after the asterix.
To make the search non greedy, you need to use .{-}
instead of .*
:
:%s/(.{-})here//
As stated there, you can't add the ?
char in vim after the asterix.
To make the search non greedy, you need to use .{-}
instead of .*
:
:%s/(.{-})here//
edited Jan 19 at 9:45
answered Jan 19 at 9:37
YoricYoric
1,2002810
1,2002810
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
add a comment |
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
Haha, thats something new... Thanks it worked.
– BladeMight
Jan 19 at 9:40
add a comment |
Another option is to use negative lookahead:
:%s/v^((here)@!.)* here//
v
is used for very magic to avoid escaping all over in regex.
add a comment |
Another option is to use negative lookahead:
:%s/v^((here)@!.)* here//
v
is used for very magic to avoid escaping all over in regex.
add a comment |
Another option is to use negative lookahead:
:%s/v^((here)@!.)* here//
v
is used for very magic to avoid escaping all over in regex.
Another option is to use negative lookahead:
:%s/v^((here)@!.)* here//
v
is used for very magic to avoid escaping all over in regex.
answered Jan 19 at 9:45
anubhavaanubhava
524k46323397
524k46323397
add a comment |
add a comment |