Suppose I have a String like following
@ABCD|NN12CT55|GFR
now I want to match
@ABCD|N
and replace it with
@ABCD N
regex for matching
@ABCD\|[^G]
is there a way to remove the | from the capturing group?
You can try this regex
^@[^|]*\K\|
and replace by:
" "
Explanation:
^ marks start of a string@ matches @ sign[^|]* matches anything but not pipe |\K if match being found upto previous point, then \K makes the
current position as starting point therefore the previous part wont
be replaced\| matches the pipe --> this pipe is going to be replaced| and once the | occurs it stops resetting the start?^?
@(TEST)\|\1replace with@\1 \1@ABCD|NN12CT55|GFRis input. and maybe a little explanation what it does?(@ABCD)\|(?!G). Or(@ABCD)\|([^G]).