【IT专家】正则表达式匹配空格,但不在“字符串”中
颜文字-空间流言
本文由我司收集整编,推荐下载,如有疑问,请与我司联系
正则表达式匹配空格,但不在“字符串”中
正则表达式匹配空格,但不在“字符串”中[英]Regex matching spaces,
but not in
“strings” I am looking for a
regular exression matching spaces only if thos
spaces are
not
enclosed in double quotes
(“). For example, in
我正在寻找一个常规的 exression
匹配空格,只有当 thos 空格没有用双引号(“)括起
来时。例如,在
Mary
had “a little lamb” it should match the first an
the second space, but not the
others.
它应该匹配第一个和第二个空间,而不是其他空间。
I want to split the
string only at the spaces which are not in the
double quotes, and
not
at the quotes.
我想将字符串仅拆分在不在双引号中的空格处,而不是在引号处。
I am using C++
with the Qt toolkit and wanted to use
QString::split(QRegExp).
QString is very
similar to std::string and QRegExp are basically
POSIX regex
encapsulated in a class. If there
exist such a regex, the split would be trivial.
我正在使用 C ++与 Qt 工具包,并希望使用 QString ::
split(QRegExp)。 QString 与
std :: string 非常相似,而
QRegExp 基本上是封装在类中的 POSIX 正则表达式。如果
存在这样的正则表达式,那么拆分将是微不足道的。
Examples:
Mary had “a little lamb” = Mary,had,”a little
lamb”1” 2 “3 = 1” 2 “3 (no splitting at
“)abc
def=“g h i” “j k” = 12 = abc,def=“g h i”,”j
k”,=,12 Sorry for the edits, I was very
imprecise when I asked the question first.
Hope it is somewhat more clear now.
对于编辑很抱歉,当我首先提出问题时,我非常不精确。希望现在更加清晰。
7
(I
know you just posted almost exactly the same
answer yourself, but I can’t bear to
just
throw all this away. :-)