Raj
Raj

Reputation: 3462

Search and Replace with Wild Card

I have a text as below -

xA0
xA1
xB0
xB1

I would like to replace this to

(xA 0)
(xA 1)
(xB 0)
(xB 1)

How to use the wildcards in this case? Could someone please help.

Upvotes: 2

Views: 3434

Answers (2)

johannes
johannes

Reputation: 14433

Does: s/\(x[AB]\)\([01]\)/(\1 \2)/ give you the expected result?


Explinations

The general pattern of search and replace is s/pattern/replacement/. Here the first match is x[AB]. Meaning that we want an x followed by an A or a B. Using \( \) to group the match and store the result in \1. The same is done to the number, which was assumed to be 0 or 1. Finally refer back to the stored groups by \1, \2 and put it within brackets.

Upvotes: 2

Azzna
Azzna

Reputation: 77

If the text is always the same length you could a substring.

Select Substring(Column, 1, 2) + ' ' + Substring(Column, 3, 1)

If you have a value of variable length though a substring won't work.

Upvotes: 1

Related Questions