MatchSyntax

approved

by Eda

A flexible, regex-like lookups for your notes.

3 stars259 downloadsUpdated 8mo agoGPL-3.0
View on GitHub

MatchSyntax for Obsidian

A flexible, "regex-like" lookups for your notes, using the compromise match syntax.

MatchSyntax will highlight the parts of the text in your active note that match your "match-syntax" query.

Examples

Part-of-speech tags can be used for searches of grammatical parts in a note. The syntax for looking for all the adjectives followed by plural words can look like this:

https://github.com/user-attachments/assets/ff264c14-853b-473a-8b8d-c3d76994bd9a

You can do regex searches with // syntax. Let's say we want to look for any word that starts with natur and is followed by either e or al:

https://github.com/user-attachments/assets/f10bc077-7240-44c4-8aa0-0d332e20dcb6

It's always advised to be careful with regex. This will also be slower than other types of lookups.

MatchSyntax is flexible, so you can combine different types of matches. Let's say we first searched for all nouns that are followed after the word "spiritual." Then, we might realize we don't want the plural nouns. So instead, we can use an AND syntax (&&) and negative matching (!) to indicate we want to exclude plural nouns:

https://github.com/user-attachments/assets/89b3b70b-a7f9-47c8-b542-c88d7200d301

[!NOTE] MatchSyntax heavily depends on the compromise library. The matching works only with English grammar; although compromise has some "work-in-progress" for other languages, there is only English support for this plugin at the moment.

Types of matches

MatchSyntax supports most types of compromise matches that are listed below, you can also check out its documentation.

Word-matches

Direct lookups.

Tag-matches (#)

Lookups using part-of-speech tagging.

Supported tags:

#Noun
    #Singular
        #Person
            #FirstName
                #MaleName
                #FemaleName
            #LastName
    #Place
        #Country
        #City
        #Region
        #Address
    #Organization
        #SportsTeam
        #Company
        #School
    #ProperNoun
    #Honorific
    #Plural
    #Uncountable
    #Pronoun
    #Actor
    #Activity
    #Unit
    #Demonym
    #Possessive
#Verb
    #PresentTense
        #Infinitive
        #Gerund
    #PastTense
    #PerfectTense
    #FuturePerfect
    #Pluperfect
    #Copula
    #Modal
    #Participle
    #Particle
    #PhrasalVerb
#Value
    #Ordinal
    #Cardinal
        #RomanNumeral
    #Multiple
    #Fraction
    #TextValue
    #NumericValue
    #Percent
    #Money
#Date
    #Month
    #WeekDay
    #RelativeDay
    #Year
    #Duration
    #Time
    #Holiday
#Adjective
    #Comparable
    #Comparative
    #Superlative
#Contraction
#Adverb
#Currency
#Determiner
#Conjunction
#Preposition
#QuestionWord
#Pronoun
#Expression
#Abbreviation
#Url
#HashTag
#PhoneNumber
#AtMention
#Emoji
#Emoticon
#Email
#Auxiliary
#Negative
#Acronym

See more in the compromise documentation.

Wildcard-matches (./*)

The . character means any one term.

The * character means zero or more terms.

Greedy-match (+)

The+ character at the end of a tag (or .) implies the match will continue with repeated consecutive matches, as far as it can.

Optional matching (?)

The ? character at the end of a word means it is nice to have, but not necessary.

Options list (OR logic)

(word1|word2) parentheses allow listing possible matches for the word (OR logic).

RegEx-match (/<reg>/)

JavaScript regular-expressions using the /myregex/ syntax.

Note: RegEx matches should be carefully used as they can be slower than other types of lookups.

First/Last (^/$)

Something should be in the start, or end of a match.

Negative (!)

Something not-match with a leading ! character.

Range ({min,max})

A maximum, minimum number of wildcard terms.

Prefix, suffix, infix

Sub-word matches, with the regex / / characters.

AND logic (&&)

AND logic using two match statements.

@ methods

  • @hasQuote
  • @hasComma
  • @hasPeriod
  • @hasExclamation
  • @hasQuestionMark
  • @hasEllipses
  • @hasSemicolon
  • @hasColon
  • @hasSlash
  • @hasHyphen
  • @hasDash
  • @hasContraction
  • @isAcronym
  • @isKnown
  • @isUpperCase
  • @isTitleCase

Fuzzy-matches (~)

Text-matching using ~ characters. Damerau–Levenshtein distance is used to compute approximate string matches.

See more in the compromise documentation.

Installation

In Obsidian, you can go to SettingsCommunity pluginsBrowse. Then, search for "MatchSyntax" and click Install.

Or, alternatively, you can clone this repository, and move it to your vault's .obsidian/plugins directory. From there, run:

npm run build

Then, go to SettingsCommunity plugins, and activate MatchSyntax under Installed Plugins.

Usage

MatchSyntax provides two commands: "Enter match syntax" and "Clear match highlights." You can choose "Enter match syntax" to write your syntax and click "Find matches" to see the matched parts of the active note.

You can bind hotkeys for the commands by going to Community plugins, find MatchSyntax in Installed Plugins, and choosing "Hotkeys" button.

Highlights are cleared automatically when there is a change in editor. You can override this behavior by setting "Manually clear the highlights" on inside plugin settings.

TODO and Ideas

  • Custom tags
  • Add setting to display the number of matches in the status bar
  • Add a widget to the editor for input and clearing highlights

License

GPLv3

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.