1

I want to use regex to convert these:

<input type="text" name="salutation" value={salutation} />
<input type="text" name="first_name" value={first_name} />

into these:

<input type="text" name="salutation" value="" />
<input type="text" name="first_name" value="" />

So in VIM, I tried all of the following commands:

:0,$s/value={.+}/value=""/gc
:0,$s/value={(.)+}/value=""/gc
:0,$s/value={[a-zA-Z0-9_\.]+}/value=""/gc
:0,$s/value={[^}]+}/value=""/gc

But I keep getting the message Pattern not found. What did I do wrong?

1

2 Answers 2

1

When using special characters in the substitution, some quantifiers needs to be escaped.

This includes +, so you should type \+ instead.

Quantifiers, Greedy and Non-Greedy, escaping

See: 4.3 Quantifiers, Greedy and Non-Greedy.

1

Your regex was actually doing this:

:0,$s/value={.+}/value=""/gc = Reaplce the string "{.+}" with value=""

:0,$s/value={(.)+}/value=""/gc = Reaplce the string "{(.)+}" with value=""

:0,$s/value={[a-zA-Z0-9_\.]+}/value=""/gc = Reaplce the string "{X+}" with value="" where X is a any of the charachter range inside []

:0,$s/value={[^}]+}/value=""/gc = Reaplce the string "{X+}" with value="" where X is not the charachter '}'

So if you intend to use '+' as quantifier you should use '\+'. Otherwise, like in all of your patterns, an actual '+' is searched instead of 1 or more of the preceding characters

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .