regex - 正则表达式找到一行有错误的引号
问题描述
嗨,我需要帮助才能找到有错误引号的行。
1 "many word " "many word" "many word "
2 "many word " " <-Error quotation
3 "many word " "many word " " many word " " many word " " <-Error quotation
4 """ but this quotation not match
5 "\"" this is not match
6 " aasd \" " " <-Error quotation \"
only line 2 3 6 have an error quotation
i need to find a line have an error quotation by regex
https://regex101.com/r/bWBV7A/9
多谢
解决方案
利用
^[^"\n]*(?:"""|"[^\\\n"]*(?:\\.[^\\\n"]*)*"[^"\n]*)*+"
见证明
解释
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
[^"\n]* any character except: '"', '\n' (newline)
(0 or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
(?: group, but do not capture (0 or more times
(matching the most amount possible)):
--------------------------------------------------------------------------------
""" '"""'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
[^\\\n"]* any character except: '\\', '\n'
(newline), '"' (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
--------------------------------------------------------------------------------
\\ '\'
--------------------------------------------------------------------------------
. any character except \n
--------------------------------------------------------------------------------
[^\\\n"]* any character except: '\\', '\n'
(newline), '"' (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
)* end of grouping
--------------------------------------------------------------------------------
" '"'
--------------------------------------------------------------------------------
[^"\n]* any character except: '"', '\n'
(newline) (0 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
)*+ end of grouping (possessive match, no backtracking)
推荐阅读
- mysql - 多个主键的更快选择查询
- kubernetes - Kubernetes 是否缓存 docker-registry 机密?
- reporting-services - 在 SSRS 中仅允许标准订阅
- amazon-web-services - 无法验证 AWS 中 *.*.compute 内部主机名的证书
- powershell - PFX / 软件证书无法正常运行
- matlab - 为什么这些逻辑表达式会在 matlab 中生成这些答案?
- javascript - JsPDF在每个新页面上重复第一行
- php - Laravel 5.7 - 存储链接路径不正确
- apache-spark - 如何知道火花流窗口中的 RDD 是否已完成火花作业?
- ajax - 使用 ajax 调用 api 很慢