'How to inset dash between regex match?
I need to add - in between of regex match in text file. I tried this but no luck!
-L\d{1,2} # this match all I need
Sa-L1
Sa-L23
Desire output:
Sa-L-1
Sa-L-23
There are -L in the lines, but I want to change -L with digits.
Solution 1:[1]
Use
(-L)(\d)
Replace with $1-$2 or \1-\2.
See regex proof.
EXPLANATION
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
-L '-L'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of \2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ryszard Czech |
