Author Posts

October 19, 2017 at 7:46 pm

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!! 🙂 🙂

Thank you, Tom

October 19, 2017 at 8:01 pm

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

October 19, 2017 at 8:02 pm

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 '\[|\]',''

October 19, 2017 at 8:11 pm

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

October 19, 2017 at 8:57 pm

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

October 20, 2017 at 12:03 am

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

October 20, 2017 at 3:40 am

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