Regex remove character from capturing group/workaround -


suppose have string following

@abcd|nn12ct55|gfr

now want match

@abcd|n

and replace

@abcd n

regex matching @abcd\|[^g]

is there way remove | capturing group?

you can try regex

^@[^|]*\k\| 

and replace by:

" " 

explanation:

  1. ^ marks start of string
  2. @ matches @ sign
  3. [^|]* matches not pipe |
  4. \k if match being found upto previous point, \k makes current position starting point therefore previous part wont replaced
  5. \| matches pipe --> pipe going replaced

demo


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -