none
Regex fro commandline parameters RRS feed

  • Question

  • Hi Together

    Could someone help me to Group this line (-l System -p 0 -r 10 -k "Log Files from Test" -z 35 -s server-dep-102) in Groups but pair based.

    On example

    -l System

    -p 0

    -r 10

    -k Log Files from Test

    and so on.....

    All Parameters are comming from externall app and -k "Log Files from Test" comes without quotas

    i have this regex pattern for it whcich goes only until first dash - in server-dep-102 and not to the and of the word.

    I know that this happend because of this  [^-]* in pattern but i dont know how to avoid it and to match hole word which contain dash in it.

     regpattern = @"-[a-z]('[^']*'|( [^-]*)?)"

    Exact Input string with no quotas after -k = "-l System -p 0 -r 10 -k Log Files from Test -z 35 -s server-dep-102"

    Thanks in advance for your help


    • Edited by todomati Friday, October 5, 2018 11:45 AM
    Friday, October 5, 2018 8:52 AM

Answers

All replies

  • Check this expression:

       -([a-z])\s*(.*?)(?=\s+(?:-|$))

     


    • Edited by Viorel_MVP Friday, October 5, 2018 12:43 PM
    • Marked as answer by todomati Friday, October 5, 2018 12:47 PM
    Friday, October 5, 2018 12:41 PM
  • Hi Viorel

    Wow..

    Thank you very very much...Great Job.

    It took me long time cause still not familiar with grouping.

    Its working perfect.....

    Friday, October 5, 2018 12:47 PM
  • Hi Together

    Could someone help me to Group this line (-l System -p 0 -r 10 -k "Log Files from Test" -z 35 -s server-dep-102) in Groups but pair based.

    On example

    -l System

    -p 0

    -r 10

    -k Log Files from Test

    and so on.....

    All Parameters are comming from externall app and -k "Log Files from Test" comes without quotas

    i have this regex pattern for it whcich goes only until first dash - in server-dep-102 and not to the and of the word.

    I know that this happend because of this  [^-]* in pattern but i dont know how to avoid it and to match hole word which contain dash in it.

     regpattern = @"-[a-z]('[^']*'|( [^-]*)?)"

    Exact Input string with no quotas after -k = "-l System -p 0 -r 10 -k Log Files from Test -z 35 -s server-dep-102"

    Thanks in advance for your help


    Your big problem is the bad design: you are using hifen ( - ) as flag for switches and at the same time you use it as part of the argument! This is a bad design decision.

    The regex string you marked as the answer, fails to understand the last switch: -s server-dep-102

    This happens exactly because of the bad design decision of using the hifen ( - ) as part of a argument.

    The regex string can be made simpler if you use the hifen as a switch-flag only.

    Saturday, October 6, 2018 7:09 AM