mary jean ligas

mary jean ligas

  • NA
  • 420
  • 196.7k

How to use regex to insert space before the formatted text?

Feb 14 2017 8:25 PM
how to use regex to insert space before the formatted text.

Example:
string currentText = "~124|NSCREMBEN260901|E|PDDTS00000713398 HSBC0100000|METROPOLITAN BANK AND TRUST|COMPANY|/5010494003 USD 7,826,413.65";
the target format is in "|E|" and I want an output like " |E|". My current expression use was this Regex rgx = new Regex(@"(?<=\|[a-zA-Z0-9]\|)"); but the out put was incorrect the space was happen after the formatted text "|E| ". Please help me in this logic as I am not mastered using regular expression. Thank you so much

Current output(but it is not correct)
~124|NSCREMBEN260901|E| PDDTS00000713398 HSBC0100000|METROPOLITAN BANK AND TRUST|COMPANY|/5010494003 USD 7,826,413.65";
I need output like this:
~124|NSCREMBEN260901 |E|PDDTS00000713398 HSBC0100000|METROPOLITAN BANK AND TRUST|COMPANY|/5010494003 USD 7,826,413.65";

Answers (7)