Raj
Raj

Reputation: 3462

search and replace for pattern with wild cards

The line I am tyring to search and replace is this -

(assert (if (>= xAltB_0 yAltA_0) (= after_A0_B0 true) (= after_A0_B0 false)))

Now I want to replace all the occurences of B_0 by C_0 and B0 by C0.

Can I use wild-card logic of vim search and replace to do this thing?

I used this command :s/B[_]0/B\10/g but it is not really working.

Can someone help please? Thanks !

Upvotes: 1

Views: 400

Answers (1)

doctorlove
doctorlove

Reputation: 19232

[_] means one of _ i.e. precisely _
If you mean either _ or nothing say 0 or 1 of _ like this: _\?
Don't forget to put it in a group using \( and \) to use it with \1
i.e.

:%s/B\(_\?\)0/C\10/g

Upvotes: 1

Related Questions