There is a line like:
= + + + ...; = + + + ...;

It is necessary to select how many substrings of the form "= +++ ...;". Those. spaces are not taken into account, the first character is "=", then from one to no difference how many "+", and the whole character ";" completes it.

Works:

/[\+]{1,}/mx 

But as soon as I want to substitute = or; stops working. Those.

 /=[\+]{1,};/mx 

Unfortunately, it does not work.

    2 answers 2

    why are there regulars at all?

     $new = array(); $lists = explode(';', $str); foreach ($lists as $l) { $l = trim($l); if (substr($l, 0, 1) != '=') continue; $new[] = substr($l, 1); } 

    Text or: In one pass you not separately separately as many such combinations. if you still want regular

     if (preg_match_all('~\=([\+\s]+);~', $str, $m)) { print_r($m); } 
    • Regular expressions are better suited to the problem, in theory. After all (PHP, like, libpcre uses), they should be compiled into a fairly efficient machine that will run through the line smartly once and for all. By the way, your example with the cycle, by the way, ignores the advantages at all, and will happily accept “ = +++ ; "And" = abc ; ". - drdaeman
    • Thank. This expression works! I only study regulars for a couple of hours)) And at this last moment I was stuck for a long time ... PS This is a lab for designing a lexical analyzer through regular expressions. Without them in any way) Without them I did in the previous one) - Ray

    I suppose it's a matter of spaces.

    If so, then it may help /=[+\s]+;/m

    ( {1,} is the same as + ; and in [...] plus, it seems, you can avoid escaping.)

    • not. the ellipsis at the end is an unlimited number of pluses) - Ray
    • No, no, no, I mean that /A{1,}/ and / A + / are the same thing, and find A , AAA and AAAAAA . Just instead of {1,} you can write + . - drdaeman
    • Aaaa! Thank. I will know) - Ray