使用 grep 获取包含单引号或双引号的字符串
Get occurrence of string, containing single or double citation marks using grep
我正在检查 language.ini 中翻译字符串的使用情况。项目中的开发人员使用 ''
,但甚至可能使用 ""
,因为 PHP 允许两者(即使它们之间存在很大差异)。
还有变量的使用;
$thisText = !true ? 'Xyz' : 'Abcd';
$this->translate($thisText);
问题是正确地包装包含单引号或双引号的表达式 - 类似于 ["']translation string["']
有没有办法用 grep 检查文件是否在 Bash 命令行中出现类似的东西?
例子
file a.php, b.php, c.phtml, d.js
a.php:
$transString = rand(0,42) == 42 ? 'Search results' : 'Nothing found';
$this->translate($transString);
b.php:
//translate 'Location'
return $this->translate("Location");
c.phtml:
<?= $this->translate('Location'); ?>
d:
trans.translate('current_location');
想要匹配 translate("Location")
或 translate('Location');
和 'Location'
如果我寻找例如。 "42"
它应该寻找 "42"
'42'
您可以使用 grep -e
来 grep 多个模式
echo -e "translate('location')\ntranslate(\"location\")" | grep -F -e "translate('location')" -e 'translate("location")'
刚才忘记逃跑了"[\"']"
egrep -r --include=\*.{php,phtml,js} --exclude-dir={languages} "[\"']${term}[\"']" ./
我正在检查 language.ini 中翻译字符串的使用情况。项目中的开发人员使用 ''
,但甚至可能使用 ""
,因为 PHP 允许两者(即使它们之间存在很大差异)。
还有变量的使用;
$thisText = !true ? 'Xyz' : 'Abcd';
$this->translate($thisText);
问题是正确地包装包含单引号或双引号的表达式 - 类似于 ["']translation string["']
有没有办法用 grep 检查文件是否在 Bash 命令行中出现类似的东西?
例子
file a.php, b.php, c.phtml, d.js
a.php:
$transString = rand(0,42) == 42 ? 'Search results' : 'Nothing found';
$this->translate($transString);
b.php:
//translate 'Location'
return $this->translate("Location");
c.phtml:
<?= $this->translate('Location'); ?>
d:
trans.translate('current_location');
想要匹配 translate("Location")
或 translate('Location');
和 'Location'
如果我寻找例如。 "42"
它应该寻找 "42"
'42'
您可以使用 grep -e
来 grep 多个模式
echo -e "translate('location')\ntranslate(\"location\")" | grep -F -e "translate('location')" -e 'translate("location")'
刚才忘记逃跑了"[\"']"
egrep -r --include=\*.{php,phtml,js} --exclude-dir={languages} "[\"']${term}[\"']" ./