开发者

regular expression to extract strings from smarty files

开发者 https://www.devze.com 2023-01-22 16:36 出处:网络
i have a batch of Smarty files that i need to ext开发者_运维知识库ract strings from, the 2 formats i need to extract from are :

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

精彩评论

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