开发者

regular expression to extract strings from smarty files

i have a batch of Smarty files that i need to ext开发者_运维知识库ract strings from, the 2 formats i need to extract from are :

format 1 : {lang mkey='some_str'}
format 2 : {lang skey='some_other_str'}

i need the output to be :

some_str
some_other_str

i'm using php, thanks in advance, sorry for the newbie question but i'm very new with regex.


<?php
  $results = array();
  preg_match_all("/[ms]key='(.+?)'/", $input, $results, PREG_PATTERN_ORDER);
  echo $results[1]."\n";
?>

EDIT: Because apparently sometimes non-greedy matching is needed on the sample data...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜