useCase
useCase

Reputation: 1275

Add some text using Regular Expression

I have mobile number series like this

9777358594
9861312901
8895210866
9861415461
9178146387
9853805726
9040663961

And I want replace them with this

a,9777358594
a,9861312901
a,8895210866
a,9861415461
a,9178146387
a,9853805726
a,9040663961

What is the regular expression to do this?

Upvotes: 1

Views: 8726

Answers (3)

Peter Long
Peter Long

Reputation: 4012

If you are using vim, try:

%s/^\d\+/a,&/g

or simpler:

%s/^/a,/g

Upvotes: 0

Tudor Constantin
Tudor Constantin

Reputation: 26861

Won't that be much easier/cleaner with simpler string operations?

serial_no = sprintf('a,%s',serial_no);

Upvotes: 0

Emre Yazici
Emre Yazici

Reputation: 10174

The matching pattern should be ([0-9]+) and replace pattern should be a,\1.

If you are using a specific language (eg. PHP, JAVA etc.) it may slightly differ.

Upvotes: 1

Related Questions