[英]regex - match punctuation at end of word in Java/Scala String
[英]Java/Scala regex, match all till word
我正在编写将 arguments 的多个变体作为一个字符串的程序。 我想通过正则表达式解析和验证这个字符串,但不幸的是我没能写出足够好的正则表达式。
所以基本上正则表达式应该匹配这个:
--image path_to_image 可选(转换器数组,如 --flip x --brightness 60)(输出数组)--output-console --output-file file_path
现在我将为我的程序编写一些有效的字符串:
--image image.jpg --output-console --output-file output.jpg
--image image.jpg --flip x --output-console --output-file output.jpg
--image image.jpg --flip x --brightness 60 --invertor --output-console
我最好的尝试是这样的:
1. 2. 3.
--image ([^\s]+) (.*?--output)(-.*$)
我的问题是第二组也将 --output 带入该组或
--image ([^\s]+) (.*?) (--output-.*$)
在这里,如果我编写没有转换器的命令,--output 将位于第二组。
如何指定只是可选的正则表达式组,并在遇到 --output 时结束?
这不是一个答案,但它将极大地帮助您编写正确的正则表达式。 在上半部分输入正则表达式,在下半部分输入您要搜索的文本,它将显示您的正则表达式找到的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.