> [!column|flex no-title] >> [!menu-dark-red|ttl-c] [[Obsidian TTRPG Tutorials]] / [[Plugin Tutorials]] / [[RegEx]] / [[Regex Pipeline - Convert External Links]] > [!column|4 no-title] >> [!menu-green-1|ttl-c] [[Getting Started]] > >> [!menu-green-2|ttl-c] [[Plugin Tutorials]] > >> [!menu-green-3|ttl-c] [[Community Supported Games]] > >> [!menu-green-4|ttl-c] [[Obsidian TTRPG Tutorials/Templates/Templates\|Templates]] > [!column|3 no-title] >> [!patreon|ttl-c] [Patreon](https://www.patreon.com/JPlunkett) ([Starter Vault](https://www.patreon.com/posts/obsidian-patreon-96801399)) > >> [!discord|ttl-c] [Obsidian TTRPG Community Discord](https://discord.gg/CdM9UCJdwU) > >> [!discord|ttl-c] [Obsidian Official Discord](https://discord.gg/8AF29UBUCa) **Usage:** Sometimes when you paste content (using Ctrl+V) the pasted content contains links to external websites. A common example is DnDBeyond. The content is linked to other DnDBeyond pages. Which is great, except I like to have the links point to my own notes instead of the online DnDBeyond versions. This Regex Pipeline example allows me to highlight text within my note and quickly convert any external links ([Link Name]\(linkurl\)) to internal links (\[\[linkurl\]\]). ##### Regex Pattern ```` "\[(.+?)\]\(.+?\)" -> "[[$1]]" ```` Lets break the Regex pattern down. | Regex Pattern | Highlighted Explanation | | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `\[`(.+?)\]\(.+?\) | This allows the pattern to search for `[`. Note the `\` in front of it. Regex uses `[` as part of the code for it's queries. Thus we need to escape the character which tells Regex that we instead want to search for the character `[` and not use it as part of a query. | | \[`(`.+?`)`\]\(.+?\) | Everything between the brackets is saved to a variable allowing us to use that information later. The first set of brackets can be referenced with `$1`. | | \[(`.`+?)\]\(.+?\) | The period (.) represents the wildcard character. Any character (except for the newline character) will be matched by a period in a regular expression. | | \[(.`+`?)\]\(.+?\) | The plus (+) symbol tells the pattern to include results that continue to match the rule. Without the + it will only find 1x character, with the plus it will find a whole word. | | \[(.+`?`)\]\(.+?\) | This means we want a non-greedy match. Which basically means to search for the smallest string which will match the pattern. | | \[(.+?)`\]`\(.+?\) | This allows the pattern to search for `]`. Note the `\` in front of it. Regex uses `]` as part of the code for it's queries. Thus we need to escape the character which tells Regex that we instead want to search for the character `]` and not use it as part of a query. | | \[(.+?)\]`\(.+?\)` | This is a repeat of the examples above. | | `->` | This is part of the Regex Pipeline plugin. The plugin `Finds` text above this using the pattern we define and `Replaces` the found text with the text provided below the `->`. | | "\[\[$1\]\]" | This will replace the found pattern with this text. The $1 will be converted to match the content stored in the `()` above. |