Home > Blockchain >  How to remove certain prefix using regex
How to remove certain prefix using regex

Time:10-02

My User data can come in any of the following 3 ways -

user="dc\AAA", user="BBB", user=CCCC,

Now, the bottom two I am able to extract it easily but issue comes when user data has an additional prefix of "dc" to it

I am trying to remove that prefix using regex and format all user data in single regex as below, but the unable to do so

user=AAA user=BBB user=CCC

Can someone please help.

CodePudding user response:

This regex should do the work: (?:.*\\)?(.*). Let's split this regex into parts:

  • (?: ) - A non-capturing group
  • .*\\ - Any characters many times, trailing by backslash
  • ? (after the brackets) indicates the data in the brackets may occur once or not at all
  • (.*) Any characters

Overall - Capturing the data after the backslash if exists

I suggest using this amazing website for trying regex

  • Related