Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency symbols don't get highlighted if not followed by a number #264

Open
the-solipsist opened this issue Nov 28, 2022 · 4 comments
Open

Comments

@the-solipsist
Copy link
Contributor

In this example, I would expect both instances of to get highlighted, but only the one followed by the number gets highlighted. So negative numbers with the minus sign after the currency symbol, or currency symbols following numbers don't get highlighted.
image

mhansen added a commit that referenced this issue Dec 2, 2022
This doesn't fix it, just captures the problem
@mhansen
Copy link
Owner

mhansen commented Dec 2, 2022 via email

@the-solipsist
Copy link
Contributor Author

the-solipsist commented Dec 3, 2022

Here's a robust pattern, that allows for rates in the form of @@/ @ and comments using ;/#/* as well. It tries to follow hledger's logic as far as I can tell.

In .NET/C#:
(?<=\S+[ ]{2,}@?[^;#*\n]*)(""[^;\\\n]+""|[^-+.,@*;\t\n ""{}=\d]+)

in JS:
(?<=\S+[ ]{2,}@?[^;#*\n]*)("[^;\\\n]+"|[^-+.,@*;\t\n "{}=\d]+)

Explanation:

  1. Lookbehind (?<=…) to check if there's
    a. one ore more non-whitespace characters \S+
    b. followed by at least 2 blank spaces [ ]{2,}
    c. optionally followed by an @ symbol @?
    d. followed by zero or more characters that aren't comment markers [^;#*\n]*
  2. Then match either:
    a. quoted text without prohibited characters: "[^;\\\n]+"
    b. or (|) simple commodity symbol without any digits, or other prohibited characters: [^ -+.,@*;\t\n"{}=\d]+

I tried the JS version on my journal in vscode, via the find bar, it works within a split second. I'm not sure how to time it to the milliseconds.

You could translate it to the appropriate regex engine.

https://regex101.com/r/fGhYrY/6

@mhansen
Copy link
Owner

mhansen commented Dec 3, 2022 via email

@the-solipsist
Copy link
Contributor Author

Could you explain / break down your regex into parts with comments? It’s very long

I edited my reply to add an explanation:
#264 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants