逗号的简单正则表达式

时间:2012-11-14 18:04:27

标签: php regex

你好,有人可以帮我解决这个正则表达式吗

这是我的$ lang_file:

define(words_picture,"Снимка");
define(words_amount,"бр.");
define(words_name,"Име");
define(words_price_piece,"Ед. цена");
define(words_total,"Обща цена");
define(words_del,"Изтрий");
define(words_delivery,"Доставка,но няма");

这是我的代码:

$fh = fopen($lang_file, 'r');
$data = str_replace($rep,"",fread($fh, filesize($lang_file)));
fclose($fh); 
preg_match_all('/define\((.*?)\)/i', $data,$defines,PREG_PATTERN_ORDER);

当我打印$ define我得到这个:

[0] => words_picture,"Снимка"
[1] => words_amount,"бр."
[2] => words_name,"Име"
[3] => words_price_piece,"Ед. цена"
[4] => words_total,"Обща цена"
[5] => words_del,"Изтрий"
[6] => words_delivery,"Доставка" //here is the part that is missing and i need it :-)

所以当字符串中有逗号时,它会破坏字符串,并且不会返回正确的值。

1 个答案:

答案 0 :(得分:0)

尝试(koko.*?)作为匹配。这将为koko返回koko,goko。如果您希望它返回koko,goko,请删除?。设为(koko.*)。这将为koko,goko返回koko,goko

这是我用来测试我的正则表达式的网站:

http://www.cyber-reality.com/regexy.html

根据您的编辑,我会说您正在寻找(koko.*)。如果您的代码适用于其他所有代码,请使用:

preg_match_all('\(/define.*)\)/i', $data,$defines,PREG_PATTERN_ORDER);