1

I have a list of 10 digit numbers in a txt file. I want to put the same character in the beginning of all rows using regex, without changing the numbers.

I also want to put the character at the end of all rows

For example a quote character '

Set of numbers as sample:

7101756638
7101756639
7107429322
7107429323
7108270737
7109747487

When I do this:

  • Search for: \d{10,10}
  • Replace with: '\d{10,10}'

I get this:

'd{10,10}'
'd{10,10}'
'd{10,10}'
'd{10,10}'
'd{10,10}'
'd{10,10}'
1
  • Did it work? ^([0-9]{10})$ replace it with '$1? If they are not in the same line, find ([0-9]{10}) and replace it with '$1? Commented Jun 26 at 0:27

2 Answers 2

0
  • You can use (?=^[0-9]{10}$) and replace it with '.
  • You can also use ^([0-9]{10})$ and then replace it with '$1.

Notes:

  • ^: start anchor.
  • ([0-9]{10}): capture group 1, including 10 digits.
  • $: end anchor.
  • (?=): positive lookahead.
0
  • Ctrl+H
  • Find what: ^\d+$
  • Replace with: '$0'
  • TICK Wrap around
  • SELECT Regular expression
  • Replace all

Explanation:

^           # beginning of line
\d+         # 1 or more digit. you can use \d{10} if there is 10 digits or .+ to match any character
$           # end of line

Replacement:

'$0'        # the whole match surounded with single quotes

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.