2016-05-23 9 views
-4

で `\色{*}`のような文字列を削除する文字列正規表現の一致とPHP

\[\color{Blue}{4} \times 2 \times 5 \times \color{Blue}{25} = \underbrace{\color{Blue}{4} \times \color{Blue}{25}}_{100} \times 5 \times 2 = \underbrace{100 \times 5}_{500} \times 2 = 500 \times 2 = 1\ 000\] 

私はPHP

\colorと次{}\color{*}のような文字列にマッチし、削除するとその内容:

  • 色\ {青}カラー\
  • {赤}
  • など

私は(これはLatexある?)あなたはすべての\colorコマンドを削除したい場合は、私は非常に遠く... https://regex101.com/r/gM1uW3/1

+2

あなたの正規表現の味とは何ですか? –

+1

試着** [こちら](https://regex101.com/r/gM1uW3/2)** – rock321987

+0

期待する結果の文字列は何ですか? –

答えて

2

ないと思う、あなたは一緒に得ることができる:

\\color\S+ 
# look for \\color literally 
# followed by at least one (but unlimited times) 
# a non-whitespace character 

modified demo on regex101.comをご覧ください。

0

OPからの溶液。

見つかりソリューション:

preg_match_all('/\\\color\{(.*?)\}/', $latex, $matches); 

if (!empty($matches[0])) { 
    foreach ($matches[0] as $r) { 
     $latex = str_replace($r, '', $latex); 
    } 
}