How do I visual select a calculation backwards?

后端 未结 2 1782
予麋鹿
予麋鹿 2021-01-16 07:40

I would like to visual select backwards a calculation p.e.

200 + 3 This is my text -300 +2 + (9*3)
                        |-------------|*

This is text 0,2         


        
2条回答
  •  清酒与你
    2021-01-16 08:23

    This seems quite a complicated task after all to achieve with regex, so if you can avoid it in any way, try to do so.

    I've created a regex that works for a few examples - give it a try and see if it does the trick:

    ^(?:[A-Za-z]|\s)+((?:[^A-Za-z]+)?(?:log|sqrt|abs|round|ceil|floor|sin|cos|tan)[^A-Za-z]+)(?:[A-Za-z]|\s)*$
    

    The part that you are interested in should be in the first matching group.

    Let me know if you need an explanation.

    EDIT:

    ^ - match the beginning of a line

    (?:[A-Za-z]|\s)+ - match everything that's a letter or a space once or more

    match and capture the following 3:
    ((?:[^A-Za-z]+)? - match everything that's NOT a letter (i.e. in your case numbers or operators)

    (?:log|sqrt|abs|round|ceil|floor|sin|cos|tan) - match one of your keywords

    [^A-Za-z]+) - match everything that's NOT a letter (i.e. in your case numbers or operators)

    (?:[A-Za-z]|\s)* - match everything that's a letter or a space zero or more times

    $ - match the end of the line

提交回复
热议问题