Giter Club home page Giter Club logo

Comments (4)

mhansen avatar mhansen commented on July 21, 2024

from hledger-vscode.

the-solipsist avatar the-solipsist commented on July 21, 2024

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

from hledger-vscode.

mhansen avatar mhansen commented on July 21, 2024

from hledger-vscode.

the-solipsist avatar the-solipsist commented on July 21, 2024

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)

from hledger-vscode.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.