Php 用于提取javascript方法调用的正则表达式
我已经为javascript文件的翻译创建了字符串提取器。 我找到了作为起点()的jsgettext项目 它使用reqular表达式在javascript文件中查找对Php 用于提取javascript方法调用的正则表达式,php,javascript,preg-match,Php,Javascript,Preg Match,我已经为javascript文件的翻译创建了字符串提取器。 我找到了作为起点()的jsgettext项目 它使用reqular表达式在javascript文件中查找对\uu()方法的调用。已成功找到简单调用,但无法找到带有参数的调用,如\uuu('string',{a:'b'}) 我试图修改正则表达式,使其也与带有参数的方法调用相匹配,但没有成功(我不是正则表达式专家) 我的问题是:如何修改以下正则表达式以匹配这样的字符串? // this is catched successfully //
\uu()方法的调用。已成功找到简单调用,但无法找到带有参数的调用,如\uuu('string',{a:'b'})
我试图修改正则表达式,使其也与带有参数的方法调用相匹配,但没有成功(我不是正则表达式专家)
我的问题是:如何修改以下正则表达式以匹配这样的字符串?
// this is catched successfully
// var string = __("Please enter %number% more characters.");
// this is problematic
var string = __("Please enter %number% more characters.", { '%number%' : 2 });
正则表达式:
$keywords = join('|', array('__'));
preg_match_all('# (?:' . $keywords . ') \(\\ *" ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)"\\ *\) #ix', $content, $matches, PREG_SET_ORDER);
$keywords=join(“|”,数组(“|”);
preg\u match\u all(“\”(?:“.$关键字”)\(\*”((?:(?>[^“\ \ \ \ \ \])+)(我不认为你真的需要匹配整个通话,比如:
__("Please enter %number% more characters.", { '%number%' : 2 });
您只需匹配:
__("Please enter %number% more characters.",
其余部分保持原样,因为这些是唯一不应该作为数据库内翻译的一部分的参数
因此,在行上编辑正则表达式并以*(?:\)\124;、)\ ix(而不是*\)\ix(而不是*)\code>结束应该足够好了。这个$keywords=join(''124;',array('uuuuu');
对我来说没有意义……这是为了匹配其他i18n函数。我从问题中删除了那个代码。