Ralluhb
Ralluhb

Reputation: 225

PowerShell regular expression /regex to replace a comma separated string of text

My current problem is that I have a string like this:

A1=ExampleText,B2=ExampleText,B2=ExampleText

I want to replace the 'T1=' and 'B2=' with a blank space so I send up with a string like this:

ExampleText,ExampleText,ExampleText

I have tried to use this piece of code

"A1=ExampleText,B2=ExampleText,B2=ExampleText" -replace '=([$,]*)'

This only removes the = sign, also want to remove the A1,B2...

A1ExampleText,B2ExampleText,B2ExampleText

can anyone please provide a regular expression to do that and explain how?

Upvotes: 1

Views: 1208

Answers (1)

SamWhan
SamWhan

Reputation: 8342

I think

\w+=

will do it for you.

It simply matches a number if word characters (a-z, A-Z, 0-9 & _), at least one, followed by an equal sign. Replacing that with '' should do it.

Check it out here at regex101.

Upvotes: 1

Related Questions