> [!column|flex no-title]
>> [!menu-dark-red|ttl-c] [[Obsidian TTRPG Tutorials]] / [[Plugin Tutorials]] / [[RegEx]] / [[Regex Pipeline - Convert to Encounter]]
> [!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:** You can type a number and then name of a monster > highlight the text > right click and select > Regex Pipeline: Convert to Encounter. It will wrap the name of the monster in the syntax required to use the monster in an encounter block using the [Initiative Tracker Plugin](obsidian://show-plugin?id=initiative-tracker). The number is used to add the number of monsters included in the combat. Note that the monster name needs to match the name of the monster within the plugin. Therefore it only needs to be a singular monster, don't use plurals.
**Example:** 4 Goblin
**Converts to: **
````
```encounter-table
name: Goblin
creatures:
- 4: Goblin
```
````
##### Regex Pattern
````
"([0-9]+) ([\w \(\)]+)"
->
"```encounter-table
name: $2
creatures:
- $1: $2
```"
````
Lets break the Regex pattern down.
| Regex Pattern | Highlighted Explanation |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `(`[0-9]+`)` `(`[\w \(\)]+`)` | 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` and the second second of brackets can be referenced with `$2`. So basically, the number is saved to `$1` and the monsters name is saved to `$2`. |
| (`[0-9]`+) ([\w \(\)]+) | This is searching for everything that matches the pattern between the square brackets. In this case it is searching for numbers and will find anything that matches 1234567890. |
| ([0-9]`+`) ([\w \(\)]+) | This first part of this searches for numbers, but on it's only will only find single numbers (`1`23) . The `+` tells the query to search for text that repeats the pattern more than once (`123`) and therefore finds the whole number. |
| ([0-9]+) (`[\w \(\)]`+) | This is searching for everything that matches the pattern between the square brackets. Lets break the middle down further. |
| ([0-9]+) (\[`\w` \\(\\)\]+) | This is shorthand (a shortcut) that matches `A-Za-z0-9_`. [Learn More](https://www.regular-expressions.info/shorthand.html) |
| ([0-9]+) (\[\w` `\\(\\)\]+) | There is a space here, this allows the pattern to includes spaces. |
| ([0-9]+) (\[\w `\(`\\)\]+) | 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. |
| ([0-9]+) (\[\w \\(`\)`\]+) | 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. |
| ([0-9]+) (\[\w \\(\\)\]`+`) | Without the `+`, the query will only find a single character that matches the pattern. The `+` tells it to reuse the pattern as long as the pattern is found. Basically this allows it to find whole words or paragraphs. |
| `->` | 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 `->`. |
| "\`\`\`encounter-table | This will replace the found pattern with this text. |
| name: $2 | This will replace the found pattern with this text. However the `$2` is converted to match the text found using the pattern that is returned from the second set of brackets. |
| creatures: | This will replace the found pattern with this text. |
| - $1: $2 | This will replace the found pattern with this text. However the `$1` is converted to match the text found using the pattern that is returned from the first set of brackets and the `$2` is converted to match the text found using the pattern that is returned from the second set of brackets. |
| \`\`\`" | This will replace the found pattern with this text. |