문제

I have a string like:

$str = "\textaolig 3 \texthtbardotlessjvar  \textrthooklong
    B \textbenttailyogh ; \textinvomega q \textscaolig
    . \textbktailgamma p \textinvsca r \textscdelta
    D \textctinvglotstop ! \textinvscripta s \textscf
    2 \textctjvar I \textlfishhookrlig t \textsck";

And I wanna get all the TeX commands (\textaolig etc.) with a regular expression. I tried:

\\([[a-z]\s]+)

But with no luck. Can someone help me out?

Kind regards,

도움이 되었습니까?

해결책

First of all, you have to enclose your string with single quotes because when using double quotes if you use a backslash it will try to escape a character, which isn't your case.

Secondly, you have to use \\\\ to match a backslash.

I don't know about TeX commands, but I've tried to match [\w\s\.;]+ so correct it if needed:

$str = '\textaolig 3 \texthtbardotlessjvar \textrthooklong
    B \textbenttailyogh ; \textinvomega q \textscaolig
    . \textbktailgamma p \textinvsca r \textscdelta
    D \textctinvglotstop ! \textinvscripta s \textscf
    2 \textctjvar I \textlfishhookrlig t \textsck';
    preg_match_all('/\\\\(?P<tex>\w+)/s', $str, $m);

    var_dump($m["tex"]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top