[英]ack: Escape single quotes while providing regex
I am using ack to search for all values of width enclosed within single or double quotes.我正在使用 ack 搜索包含在单引号或双引号内的所有宽度值。
Ex: width="23"
, width='420'
例如:
width="23"
, width='420'
RegEx Pal confirms /width=("|')\d+\1/g
is the right regex for the job. I am however finding it difficult to supply this regex to ack. RegEx Pal 确认
/width=("|')\d+\1/g
是适合这项工作的正则表达式。但是我发现很难提供这个正则表达式来确认。
<prompt>$ ack 'width=("|\')\d+\1'
<--- Escaping the '
in the regex like \'
did not help <prompt>$ ack 'width=("|\')\d+\1'
<--- Escaping 正则表达式中的'
像\'
没有帮助
<prompt>$ ack 'width=("|\\\')\d+\1'
<--- Neither did this. <prompt>$ ack 'width=("|\\\')\d+\1'
<--- 这也没有。
Any ideas?有任何想法吗?
"width=['\"]\d+['\"]"
works for me.为我工作。 The square brackets define a set of characters containing
'
(by itself) and \"
(espaced because of the surrounding double-quotes).方括号定义了一组包含
'
(单独)和\"
(因为周围的双引号而被分隔)的字符。
It also works with grep, but you need the -P
option because \d+
is not part of standard grep regex.它也适用于 grep,但您需要
-P
选项,因为\d+
不是标准 grep 正则表达式的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.