Reputation: 11
I have a file with a file with lines containing a space, 9 digits, 6 spaces and 5C18. Finding it is easy I'm using
\s\d{9}\s{6}\5C18
The problem is that I need to replace the space at the beginning of the line with a letter, say F. So that everything else remains in tact. Every time I try to do it the entire line is replaced with the expression. I know this is probably something stupidly basic but any help would be appreciated.
Upvotes: 0
Views: 77
Reputation: 726599
Move the part that you do not wish to replace into a lookahead expression:
^\s(?=\d{9}\s{6}5C18)
Now the portion in (?= ... )
is not considered part of the match; only the initial space is. Hence, running a replace with this regex would let you replace the initial space with whatever characters that you want.
It's text on a single line. The F needs to go where that first space is at the beginning of the line.
Note the use of ^
anchor to ensure that the match of the initial space is tied to the beginning of the line.
Upvotes: 1