# Bulk Rename regex help

**URL:** <https://forum.obsidian.md/t/bulk-rename-regex-help/66851>\
**Category:** Help\
**Created:** [September 8, 2023, 5:46am UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851 "2023-09-08T05:46:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![svr](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@svr](https://forum.obsidian.md/u/svr)\
**Post date:** [September 8, 2023, 5:46am UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/1 "2023-09-08T05:46:15Z")

</div>

I am trying to rename 3k notes that were imported from Reflected app with broken names using the `Bulk Rename` plugin. It is awesome, but i struggle with RegEx. The pattern of names is not the same for the whole set of notes, but the majority of them have the following pattern: `ABC p0000 ABC`, where `0000` is actually incrementing from `1` to `3999` across the set of notes, so there are only unique numbers after `p`. So the first note is for example `ABC p1 ABC`, second is `BOB p2 BOB`, third is `Obsidian p3 Obsidian` and so on.

What I need is to cut everything so that the name becomes just `ABC`

### I am not good with RegEx and Claude-2 is writing me complete bullshit instructions - regex he provides either does not work or does not find notes. Maybe I am bad in prompting, too 🙂

I’ve searched by RegEx, but no success so far. Please help somebody

---

<div class="post-metadata">

**Author:** ![gino\_m](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gino\_m](https://forum.obsidian.md/u/gino_m)\
**Post date:** [September 8, 2023, 12:29pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/2 "2023-09-08T12:29:14Z")

</div>

From what I’ve seen from your requirement, it should not be so difficult. But there are some caveats. For example, files that may get renamed but should not must be first moved from the directory. Do you know how to take these precautions?

Also, as on StackOverFlow as well (where you can also put up a request), they want clear instructions because we want to make sure we don’t cause harm.

Use code blocks as well when you rewrite instructions: 4-5 instances of filenames that match a pattern and required result in a different block. We need to see clear.

Also, a tip:  
If you are on Windows, install voidtools - Everything proggy. Select all files for rename (F2) and you can see when you make regex changes what would change to what before hitting rename. It is very helpful.

---

<div class="post-metadata">

**Author:** ![svr](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@svr](https://forum.obsidian.md/u/svr)\
**Post date:** [September 8, 2023, 8:53pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/3 "2023-09-08T20:53:07Z")

</div>

Thank you so much for your reply! I am not on Windows.

I think I know how to move files from one directory to another, but if i need to go through my 4 thousand notes to decide which ones should I move and which should stay, I might as well just rename all those 4 thousand notes. Maybe I did not get your idea correctly?

I thought that RegEx would just ignore those notes that have a different pattern in their name? Anyway, let me provide a couple of examples.

I actually have two recurring patterns after the migration.

The **first** one is exactly like I described above.

The format for examples is following:  
`Note title I currently have` \>\>\> `Note title I want after RegEx transfornation`

Ex. 1: `SDT p2313 SDT` \>\>\> `SDT`  
Ex. 2: `Saturation p2415 Saturation` \>\>\> `Saturation`  
Ex. 3: `Section p2427 Section` \>\>\> `Section`  
Ex. 4: `Scheme 1 p2217 Scheme 1` \>\>\> `Scheme 1`

The **second** pattern is a little bit different. Those notes have a name of the note followed by a long sequence of letters and digits that looks like a hash. The format of examples would be the same as for the first pattern.

Ex.1: `DNA db60e6524e3a463a8990ec8d1135d870` \>\>\> `DNA`  
Ex. 2: `European Union 8bc25ea6eccc4ea19ac2eb58122add14` \>\>\> `European Union`  
Ex.3: `equity 370a65f13528475b8b203198fd1d433b` \>\>\> `equity`.

Hope I correctly grasped the idea of clarity, would really appreciate any help, and thanks once again for helping me out!

---

<div class="post-metadata">

**Author:** ![gino\_m](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gino\_m](https://forum.obsidian.md/u/gino_m)\
**Post date:** [September 8, 2023, 9:01pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/4 "2023-09-08T21:01:13Z")

</div>

Basically you need to match one or two (possibly more) strings and slash off from where a string made up of letters and digits starts?

How many notes are there that have digits in filenames that you would want to keep?  
Apart from `Scheme 1`?

- Which is not a single string, of course…

We need some kind of logic to deal with the majority of cases. Then we’d filter down on the remainder.

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [September 8, 2023, 9:26pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/5 "2023-09-08T21:26:18Z")

</div>

Are the files already in an Obsidian vault, so that is possible to do some regex fun to check for potentially duplicates? If so, I would strongly suggest doing that before renaming stuff.

And of course do make backups before doing any major changes to your files.

---

<div class="post-metadata">

**Author:** ![gino\_m](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/g/3ec8ea/32.png) [@gino\_m](https://forum.obsidian.md/u/gino_m)\
**Post date:** [September 8, 2023, 9:50pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/6 "2023-09-08T21:50:04Z")

</div>

Yes, also, a surefire stringent regex is impossible to do without knowing or having the opportunity of taking in (“seeing”) all variety.

But I have a hunch it is not a matter of life and death here.  
It is possible that multiple matches will fight for the same new name (I guess the OS will rename them sequentially then).

Have a look at this, folks:

> **[regex101: build, test, and debug regex](https://regex101.com/r/WxZgnm/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

I did not cater to Scheme 1 because I don’t think these types would come in the large majority.

@svr, you realize more than one search and replace is needed?

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [December 7, 2023, 9:50pm UTC](https://forum.obsidian.md/t/bulk-rename-regex-help/66851/7 "2023-12-07T21:50:54Z")

</div>

Closed on December 7, 2023, 9:50pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
