# RegEx is making me tense

**URL:** <https://forums.powershell.org/t/regex-is-making-me-tense/16408>\
**Category:** PowerShell Help\
**Created:** [May 3, 2021, 3:02pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408 "2021-05-03T15:02:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShaunBlake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/shaunblake/32/1273_2.png) [@ShaunBlake](https://forums.powershell.org/u/ShaunBlake)\
**Post date:** [May 3, 2021, 3:02pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/1 "2021-05-03T15:02:18Z")

</div>

Objective: remove (notes) from filenames e.g., Cassidy (Series) - Notebook.html

Best effort:

```auto
$TargetPath = 'C:\Users\flana\TC_temp'

Get-ChildItem $TargetPath *.html | 

    Foreach {
        rename-item $_.Fullname $_.Fullname.Replace('\(.*\) ', '')
        }

```

Result: runs with no errors but files are not renamed. What in the world am I doing wrong?

---

<div class="post-metadata">

**Author:** ![anagy](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@anagy](https://forums.powershell.org/u/anagy)\
**Post date:** [May 3, 2021, 3:14pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/2 "2021-05-03T15:14:51Z")

</div>

So you have a filename such as 'Cassidy (Series) - Notebook.html

and you’re trying to make it like 'Cassidy (Series) - book.html?

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [May 3, 2021, 3:42pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/3 "2021-05-03T15:42:12Z")

</div>

The `Replace()` method of object type `String` doesn’t support regex replacement. You could do this:

```auto
Rename-Item $_.FullName ($_.FullName -replace '\(.*\) ')

```

---

<div class="post-metadata">

**Author:** ![ShaunBlake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/shaunblake/32/1273_2.png) [@ShaunBlake](https://forums.powershell.org/u/ShaunBlake)\
**Post date:** [May 3, 2021, 3:49pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/4 "2021-05-03T15:49:59Z")

</div>

> [@anagy](#):
>
> you’re trying to make it like 'Cassidy (Series) - book.html?

No, @anagy, I want to remove the parens and all text within them, e.g., "Cassidy - Notebook.html

---

<div class="post-metadata">

**Author:** ![ShaunBlake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/shaunblake/32/1273_2.png) [@ShaunBlake](https://forums.powershell.org/u/ShaunBlake)\
**Post date:** [May 3, 2021, 3:55pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/5 "2021-05-03T15:55:57Z")

</div>

> [@matt-bloomfield](#):
>
> `Rename-Item $_.FullName ($_.FullName -replace '\(.*\) ')`

@matt-bloomfield I surely must have read that but could not get it right. Thanks a BUNCH, it is what I needed. (Here comes a stealth hug!)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:26pm UTC](https://forums.powershell.org/t/regex-is-making-me-tense/16408/6 "2024-05-16T20:26:31Z")

</div>


