2016-05-23 8 views
-4

Dieser StringRegex und entfernen Sie Zeichenketten wie ` color {*}` in 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\] 

I übereinstimmen soll, und entfernen Sie Strings wie \color{*} in PHP

\color und die nächste {} und deren Inhalt :

  • \ color {Blau}
  • \ color {Red}
  • usw.

Ich glaube, ich bin nicht sehr weit ... https://regex101.com/r/gM1uW3/1

+2

Was ist Ihr regex Geschmack? –

+1

versuchen ** [this] (https://regex101.com/r/gM1uW3/2) ** – rock321987

+0

Was ist Ihre erwartete Ergebniszeichenfolge? –

Antwort

2

Wenn Sie alle \color Befehle entfernen möchten (das ist Latex?), Können Sie mit auskam:

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

Sehen Sie Ihre modified demo on regex101.com.

0

Lösung von OP.

gefunden Lösung:

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

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