Find and Replace Bear Header WikiLinks "/" with Obsidian "#" for all notes

What I’m trying to do

Repair the Bear wikilinks to headers after import so they work in Obdsidian (change / to #)

Things I have tried

Variations of Find & Replace, search for relevant plugins, search of help and web.

I feel I should be able to figure this out, but alas…

Bearing in mind potential helpers are not familiar with Bear links and that these changes are destructive, could you give us a few examples, still?

Of course. After using the new Importer plugin for an import of Bear notes, one is left with the Bear formatting for wikilinks to note headers.

For example,

A Bear wikilink to the Header “Deep Links” inside the note “Obsidian”:

[[Obsidian/Deep Links]]

An Obsidian wikilink to the Header “Deep Links” inside the note “Obsidian”:

[[Obsidian#Deep Links]]

In my case, there are several hundred of these and so I’m hoping to avoid manual changes.

Are there aliases to think of with pipe character?

No, none.

You can use VS Code, Sublime Text, Notepad++ text editors to search and replace with regex match on.
Are you familiar with one of these?
Some tutorial in Notepad++:

The match and replacements are easy enough. See:

  • Edit: gave you a more stringent one.

Thanks @gino_m , I’ll check them out.

I’ll be around for a while.

Just tell us what program you’ve managed to install or what more instructions you need.

I hate to be a tech wuss but I think this solution is over my head.

Either the Format Converter core plugin needs to be updated to convert Bear wikilinks into Obsidian wikilinks or that functionality needs to be added to the new Importer plugin.

You might try filing it as a feature request. I migrated from Bear to Obsidian back when Obsidian was still in beta and before Bear even had wikilinks and they were still using :: instead of == for highlights, and it looks like the Format Converter hasn’t been updated at all since then.

2 Likes

I assume the regular expression is the part that seems complicated. Here is a less complex (but still hard to read) one with explanation.

Before making a sweeping change like this, make sure your backups of the notes are up to date.

Basics

Put this in the “Find” field:

(\[\[[^\/]+)\/

This matches 2 square brackets followed by 1 or more characters that aren’t /, followed by a / — for example, [[Obsidian/.

Put this in the “Replace” field:

$1#

This is the matched text before the slash ([[Obsidian), followed by a # (resulting in [[Obsidian#).

Details

There are a lot of \ characters. That marks the character after it as not special, and is needed when you want to match a character that is used in regular expression syntax.

  • The \/ at the end matches /.
  • ( and ) mark a sub-pattern separate from the rest. Within that:
    • \[\[ matches [[.
    • [^\/]+ matches 1 or more characters that aren’t /.
      • The brackets mark the contents as a group or range.
      • ^ within brackets means “not”.
      • \/ matches /.
      • + means “1 or more of the preceding”.
4 Likes

The solution is to find across all md files in a folder (your vault) text that we convert. Because every string within the double square brackets (in your Bear Wikilinks) is different, we use regular expressions to match all of them and make the conversion. So it is like normal search and replace but you tick a regex box in a text editor that is capable doing these changes (I listed 3 for you) and of course add your folder where the vault is located.
In the gif animation I linked I showed how to do this in a different scenario, thinking it would be enough.

My regular expression also works and now you’ve got a new one as well. The more the merrier…

1 Like

Many thanks to @gino_m and @CawlinTeffid for all of their assistance. I have successfully searched for all instances in Obsidian and also using BBEdit vault-wide. The replace function is useful for a single file in Obsidian but there is no vault-wide search and replace at this time so I’ve managed to isolate approximately 40 key instances which I will update manually for the time being.

I will continue to learn more about regular expressions and regex – a million future uses.

Per the wise suggestion of @Synchronicity I have added this to feature requests.

The day job beckons.

Again, I really appreciate all of your help with this.

1 Like

Steve, if you are on a Mac, I’m pretty sure you can install Sublime Text (free, supporting the devs is optional), where when pressing CMD+SHIFT+F you can specify your vault location in ‘Where’, then copy and paste the match and replacement lines from my own or Cawlin’s example, tick the regex icon (the dot and asterisks one on the left) and you’re good to go.

1 Like

As Gino says, you’ll need an external app to do a regex search-replace across files — see their earlier posts for suggestions. (There are plugins to do regex search-replace and to do search-replace across files, but last I knew there isn’t one that does both.)

(As a side note, when you don’t need regex the built-in search-replace works pretty well across a not-too-huge number of files. It stays open when you switch to a new note, so you can click a search result , click “Replace All”, and repeat pretty quickly.)

1 Like

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