Scott: I started going down this path, trying to figure out a way to ‘count’ the characters from ‘(‘ to ‘)’ and then replace those positions, but then remembered RegEx is pretty much built for this type of thing and abandoned it. Thanks for sharing.
Thanks, Geoff From: [email protected] [mailto:[email protected]] On Behalf Of Scott Crawford Sent: Wednesday, November 30, 2016 1:31 PM To: [email protected] Subject: RE: [powershell] Remove anything between defined characters: ATTENTION: This email came from an external source. DO NOT open attachments or click on links from unknown senders or unexpected emails. Which is much better than my way, but here it is anyway ☺ since it takes a different approach. $a = "Jessica (Yvonne)" $b = "" for ($i = 0; $i -lt $a.length; $i++) { if ($a[$i] -eq "(") {$Delete = $true} if ($a[$i] -eq ")") {$Delete = $false} if (-not $Delete -eq $true -and $a[$i] -ne ")") {$b = $b + $a[$i]} } $b.TrimEnd() From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Devin Rich Sent: Wednesday, November 30, 2016 3:15 PM To: [email protected]<mailto:[email protected]> Subject: Re: [powershell] Remove anything between defined characters: I would do it this way because i'm lazy: -replace " ?\(.*?\) ?" PS > "(ywfew) Jessica (Yvs)" -replace " ?\(.*?\) ?" Jessica PS > "(ywfew)Jessica (Yvs)" -replace " ?\(.*?\) ?" Jessica PS > "Jessica (Yvs)" -replace " ?\(.*?\) ?" Jessica Thanks, Devin Rich Systems Administrator On Wed, Nov 30, 2016 at 2:00 PM, Orlebeck, Geoffrey <[email protected]<mailto:[email protected]>> wrote: I’m working on a script that gets some data fed into it. Some of the fields have two names, one wrapped in (). Example: “Jessica (Yvonne)”. I am trying to remove everything within the (), but I’m not sure how. I’ve tried several regex expressions, and I’m able to remove the (), but not the content within them. Essentially I’d like to turn “Jessica (Yvonne)” into “Jessica” (even if there is whitespace after ‘Jessica’). I tried several suggestions I saw online, escaping the “(“ and “)”, or using $regex = [regex]::Escape('()'), but I’m not sure how to basically say “Find ‘(‘ and remove everything until ‘)’ [including the parenthesis]. Any helpful tips or links where people are doing this? I tried doing array matches, removing the () and then selecting only the first position, but then discovered some of the fields have the parenthesis first (e.g. “(Yvonne) Jessica”. Thanks for any suggestions. Confidentiality Notice: This is a transmission from Community Hospital of the Monterey Peninsula. This message and any attached documents may be confidential and contain information protected by state and federal medical privacy statutes. They are intended only for the use of the addressee. If you are not the intended recipient, any disclosure, copying, or distribution of this information is strictly prohibited. If you received this transmission in error, please accept our apologies and notify the sender. Thank you. The information contained in this message is privileged, confidential, and protected from disclosure. If you are not the intended recipient, you are hereby notified that any review, printing, dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.
