[英]Unix, how to extract values between double quotes
I have some VBA macros, and I need to translate all output messages, but these messages are enclosed between double quotes, like this: 我有一些VBA宏,我需要转换所有输出消息,但是这些消息用双引号引起来,如下所示:
If Not IsNumeric(Sheet28.Range("I9")) Then
Call MsgBox("Error! Voucher expiry years must be a number", vbDefaultButton1 Or vbExclamation, "Error!")
Application.Undo
End If
And I want this: 我想要这个:
"I9"
"Error! Voucher expiry years must be a number"
"Error!"
Is it possible to do it with grep, sed, awk, regex or something else? 是否可以使用grep,sed,awk,regex或其他方法执行此操作?
"I9" is not a message, but I'll take care of removing texts that are not messages, removing duplicates, etc. “ I9”不是消息,但我将删除非消息文本,删除重复项等。
Thanks in advance! 提前致谢!
You'll likely want a pattern such as: 您可能需要一个模式,例如:
"[^"]+" # matches I9 also
"[^)I"]+" # won't match messages starting with "I"
"[^"]+?" # lazy match in case you aren't using grep, egrep, etc.
"[^"][^0-9(]+" # won't match messages with the second character as digit.
Using grep
or egrep
: 使用grep
或egrep
:
grep -Eo '"[^"]+"'
egrep -o '"[^"]+"'
Would match "I9"
, "Error!"
将匹配"I9"
, "Error!"
, "Error! Voucher expiry years must be a number
" , "Error! Voucher expiry years must be a number
”
grep -Eo '"[^"][^0-9(]+"'
Matches "Error!"
匹配"Error!"
, "Error! Voucher expiry years must be a number"
, "I match also"
, "Error! Voucher expiry years must be a number"
, "I match also"
"
matches the character "
literally (case sensitive) "
从字面上匹配字符"
(区分大小写) [^I)"]
匹配[^I)"]
不存在的单个字符 +?
Quantifier — Matches between one and unlimited times, as few times as possible, expanding as needed (lazy) 量词-匹配一次和无限次,尽可能少的次数,根据需要扩展(延迟) Example : 范例 :
https://regex101.com/r/z2eSQF/2 https://regex101.com/r/z2eSQF/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.