user2399453
user2399453

Reputation: 3081

Regex to replace a string

In VI I need to replace a pattern that looks like this:

seq- followed by exactly 24 chars (can be 0-9, a-z, A-Z only) followed by / followed by some number of (0-9, a-z, A-Z). So an example string would be:

seq-BzFk78qrJBkbnv1KkxppsfG4/92191_A_B

I want to replace the above string with a fixed string:

seq-ID/NUM_ID

How do I do this in Vi or Vim? I tried a few things like

  :%s/seq-[a-zA-Z0-9]{24}/[a-zA-Z0-9]{+}/seq-ID/NUM_ID

But it doesnt' work..

Upvotes: 0

Views: 73

Answers (1)

redneb
redneb

Reputation: 23840

You have to be careful with how you use quantifier and you must escape the /. Try this

:%s/^seq-[a-zA-Z0-9]\{24\}\/.*$/seq-ID\/NUM_ID/

Upvotes: 1

Related Questions