Repository: platers/obsidian-linter (ts)

Issue:
Bug: Tag Regex Matches Punctuation Like `:` Which Causes Other Problems
## Is Your Feature Request Related to a Problem? Please Describe.

I have move tags to YAML turned on and when I lint the current file it moves on of the tags into the YAML but it's showing as an error (in the Obsidian Properties in Live Preview) because it is also copying the colon after the tag in my text.
![image](https://github.com/platers/obsidian-linter/assets/114887599/cfed7810-1bef-4d21-ae17-104727c7450c)

![image](https://github.com/platers/obsidian-linter/assets/114887599/58e11b19-d2cf-4b3f-b3bc-bd382d4a2958)

## Describe the Solution You'd Like

Ideally, I would like an option similar to the remove trailing punctuation in heading, but for tags.

**Example:**
Before:
``` markdown
---
tags: #tag1:
---
```
After:
``` markdown
---
tags: #tag1
---
```

## Describe Alternatives You've Considered

The only alternative I've really considered is trying to remember to add a space after tags when using punctuation after them.




Pull request:
Fix: Update Tag Regex to Better Conform to Specified Obsidian Tag Spec
Fixes #1116 

There was an issue where several things were being allowed when they should not have been in the tag regex.

[Here](https://help.obsidian.md/Editing+and+formatting/Tags#Tag+format) is the spec.

It says:

You can use any of the following characters in your tags:

- Alphabetical letters
- Numbers
- Underscore (_)
- Hyphen (-)
- Forward slash (/) for [Nested tags](https://help.obsidian.md/Editing+and+formatting/Tags#Nested%20tags)

Changes Made:
- Updated regex to conform better with the spec
- Added a test for the scenario in question


Patch:
diff --git a/src/utils/regex.ts b/src/utils/regex.ts
index e7b8552..7560a31 100644
--- a/src/utils/regex.ts
+++ b/src/utils/regex.ts
@@ -13,7 +13,8 @@ export const codeBlockRegex = new RegExp(`${backtickBlockRegexTemplate}|${tildeB
 export const wikiLinkRegex = /(!?)\[{2}([^\][\n|]+)(\|([^\][\n|]+))?(\|([^\][\n|]+))?\]{2}/g;
 // based on https://davidwells.io/snippets/regex-match-markdown-links
 export const genericLinkRegex = /(!?)\[([^[]*)\](\(.*\))/g;
-export const tagWithLeadingWhitespaceRegex = /(\s|^)(#[^\s#;.,><?!=+{`\]]+)/g;
+// based on https://help.obsidian.md/Editing+and+formatting/Tags#Tag+format
+export const tagWithLeadingWhitespaceRegex = /(\s|^)(#[\p{L}\-_\d/]+)/gu;
 export const obsidianMultilineCommentRegex = /^%%\n[^%]*\n%%/gm;
 export const wordSplitterRegex = /[,\s]+/;
 export const ellipsisRegex = /(\. ?){2}\./g;


Test patch:
diff --git a/__tests__/move-tags-to-yaml.test.ts b/__tests__/move-tags-to-yaml.test.ts
index c85dede..db370e2 100644
--- a/__tests__/move-tags-to-yaml.test.ts
+++ b/__tests__/move-tags-to-yaml.test.ts
@@ -323,5 +323,31 @@ ruleTest({
         tagArrayStyle: NormalArrayFormats.SingleLine,
       },
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/1116
+      testName: 'Make sure that ":" is not valid in a tag',
+      before: dedent`
+        ---
+        title: Note
+        Date: 2023-10-24T23:00:00+08:00
+        lastMod: 2023-11-28T17:36:29+08:00
+        tags: [text, val2]
+        ---
+        ${''}
+        #text:
+      `,
+      after: dedent`
+        ---
+        title: Note
+        Date: 2023-10-24T23:00:00+08:00
+        lastMod: 2023-11-28T17:36:29+08:00
+        tags: [text, val2]
+        ---
+        :
+      `,
+      options: {
+        tagArrayStyle: NormalArrayFormats.SingleLine,
+        howToHandleExistingTags: 'Remove whole tag',
+      },
+    },
   ],
 });