# Extract text between two underscores

**URL:** <https://forums.powershell.org/t/extract-text-between-two-underscores/13757>\
**Category:** PowerShell Help\
**Created:** [February 4, 2020, 2:00am UTC](https://forums.powershell.org/t/extract-text-between-two-underscores/13757 "2020-02-04T02:00:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aa\_meow](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@aa\_meow](https://forums.powershell.org/u/aa_meow)\
**Post date:** [February 4, 2020, 2:00am UTC](https://forums.powershell.org/t/extract-text-between-two-underscores/13757/1 "2020-02-04T02:00:16Z")

</div>

I need to rename a large number of PDF files that are in the following format:

\_TEXT[1…n]\_NAME[1…n]\_SUFFIX[1…n]

Is there a way to extract TEXT [1,2…n] (amount of characters is different for every file) between two underscores using Powershell?

Is there a way to extract SUFFIX [1,2,…n] after underscore (amount of characters is different for every file)?

I have tried Dir|Rename-Item {$.\_name -replace “…”"}. That only worked for one part of the project.

---

<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:30pm UTC](https://forums.powershell.org/t/extract-text-between-two-underscores/13757/2 "2024-05-16T20:30:44Z")

</div>

Closed on May 16, 2024, 8:30pm UTC


