Reputation: 49
Trying to remove the substring in between the braces in powershell.
$name = "Kothuru, Manoj Kumar (Happy)"
$name = "Manoj Kumar"
$name = "Manoj (end)"
I tried the below code by splitting the string by braces.
$name.Split("(")[0]
Is there any better way to do this. Since if the name doesn't contain the tail. It won't work
Upvotes: 0
Views: 42
Reputation: 24602
You can use Replacement operator. It has the following syntax.
<input> -replace <regular-expression>, <substitute>
Use \(.*?\)
pattern to match the characters between the parentheses and replace it with empty string.
$name -replace "\(.*?\)", ""
Upvotes: 2