replace regex??

Where may I find something that will help me create a proper regex for this??

$tableFragment = $tableFragment -replace '[ ]',''

Basically I need to replace (remove, really) all instances of the string from the $tableFragment string.

The way I have it that I found on the Internet does not work!! :slight_smile: :slight_smile:

Thank you, Tom

What exactly are you looking for? For literal square brackets or for spaces?

You need to use the regex backslash literal expression in front of the brackets because brackets are used in expressions. Then use a | symbol between to grab either bracket.

$tableFragment = $tableFragment -replace '\[|\]',''

Thank you everyone, Olaf asked about what I need.

The pre code in my first forum post above don’t show the string.

The string contains multiple occurrences of

table (blank space) table – as an empty table, with the html brackets around it which I can NOT reproduce here
– basically an empty table.

I want to remove ONLY all the empty tables – replace is the only way to do it b/c the string is of different lengths each time it’s generated, hence using a replace. Other tables are in the string and they contain data (rows, columns).

Thank you, Tom

I think this is what you’re after. Hoping I’ve remembered correctly that a Gist link won’t remove the angle brackets.

\s* will match 0 or more occurrences of whitespace. Unfortunately, I can’t get it working across multiple lines with -replace although the regex code to match it should just be \s*[\r\n]* (verified working on

Hello, thank you, that was perfect.

HOW did you get the code to display in your post to make the brackets appear???

I used line 2, replacing ‘foo’ with ‘’ and it works like a charm.
I added a 2nd line to remove/replace some other extraneous code too.

Thank you, Tom

Hi Tom, to post the HTML code he used a gist as discussed by Don Jones at the top of this forum in post