How to parse a command line with regular expressions?

后端 未结 13 686
离开以前
离开以前 2020-12-03 16:02

I want to split a command line like string in single string parameters. How look the regular expression for it. The problem are that the parameters can be quoted. For exampl

13条回答
  •  执笔经年
    2020-12-03 16:35

    there's a python answer thus we shall have a ruby answer as well :)

    require 'shellwords'
    Shellwords.shellsplit '"param 1" param2 "param 3"'
    #=> ["param 1", "param2", "param 3"] or :
    '"param 1" param2 "param 3"'.shellsplit
    

提交回复
热议问题