我有以下字符串
This is some testing dbo.GetPersonData(this_.PersonId,'Date contract recieved from the client') cs.dbo.Person 'this is test'
我想要它通用并获得以下结果
This
is
some
testing
dbo.GetPersonData(This_.PersonId,
'DateContract received from the client'
)
cs.dbo.person
'this is test'
我在这里想要实现的是用空格分隔单引号之间的任何内容
我试过使用
'(.*?)'|\S+
然而,它忽略了:<'Date contract recieved from the client'>
答案 0 :(得分:1)
答案 1 :(得分:1)
\S
匹配任何非空白字符,'
也匹配。
使用
'([^']*)'|[^\s']+
或者,如果您有 PCRE:
(?|'([^']*)'|([^\s']+))
见proof。
说明
--------------------------------------------------------------------------------
' '\''
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[^']* any character except: ''' (0 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
' '\''
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
[^\s']+ any character except: whitespace (\n, \r,
\t, \f, and " "), ''' (1 or more times
(matching the most amount possible))
答案 2 :(得分:-1)
您应该使用以下模板:
(\n.*?)*)\n\s*\n