Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

language agnostic - Regex match all the words outside quotation marks?

Is it possible to match text outside quotation marks by using standard regex parser? I have seen this answer, but it is done by using PCRE:

Can regex match all the words outside quotation marks?

This is not a pure solution because of using PERL. I know that it also can be solved by using programming language, but the idea is to use pure regex parser.

I have made something like this, but this is not working correctly

[^'"]*(?=(?:(['"])+(.*?1))|([^'"]*$))

Thank you in advance.

UPD1:The idea is to match any kind of text outside quotation marks, the solution must not depend on the input.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<yourtext>(?=(?:[^"]*"[^"]*")*[^"]*$)

Yes you can do it in using positive lookahead.But this assumes you have balanced " and there is no stray " lying somewhere.See demo.

http://regex101.com/r/sU3fA2/29


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...