如何在空白之间而不是引号之间进行拆分? [英] How to split on white spaces not between quotes?
本文介绍了如何在空白之间而不是引号之间进行拆分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试仅在空白( \ s
)上分割字符串,但是不在带引号"部分之间.
I am trying to split a string on white spaces only (\s
), but that are not between a "quoted" section.
我通过以下方式匹配这些引用部分之间的所有文本:
I am matching all text in between these quoted sections in the following manner:
(['"`]).*?\1
但是,当我尝试将其添加为负前瞻性时,仅在这些引号之外的空白处进行拆分时,我无法使它起作用:
However, when I try to add this as a negative lookahead, to only split on white spaces outside of those quotes, I can't get it to work:
\s(?!(['"`]).*?\1)
如何只分割不在引号"中的空白?
How can I only split on the white spaces that are not in "quotes"?
推荐答案
\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)
您可以将此正则表达式与 lookahead
一起使用.请参见演示.
You can use this regex with lookahead
to split upon.See demo.
https://regex101.com/r/5I209k/4
或混合的刻度线类型.
https://regex101.com/r/5I209k/7
这篇关于如何在空白之间而不是引号之间进行拆分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文