src/Anshar/Utils/StringHelper.php
public function collapseStartingRepetition($string)
    {
        $matches = array();
        $pattern = "/^[" . preg_quote($string, "/") . "]+(?P<remainder>.*)/";

        $starts_with_string = preg_match($pattern, $this->string, $matches);

        if ($starts_with_string) {
            $collapsed_string = $string . $matches["remainder"];

            return $collapsed_string;
        } else {
            return $this->string;
        }
    }
public function collapseStartingRepetition($string)
    {
        $matches = array();
        $pattern = "/^[" . preg_quote($string, "/") . "]+(?P<remainder>.*)/";

        $starts_with_string = preg_match($pattern, $this->string, $matches);

        if ($starts_with_string) {
            $collapsed_string = $string . $matches["remainder"];

            return $collapsed_string;
        } else {
            return $this->string;
        }
    }
public function collapseStartingRepetition ( $ string ) { $ matches = array ( ) ; $ pattern = "/^[" . preg_quote ( $ string , "/" ) . "]+(?P<remainder>.*)/" ; $ starts_with_string = preg_match ( $ pattern , $ this -> string , $ matches ) ; if ( $ starts_with_string ) { $ collapsed_string = $ string . $ matches [ "remainder" ] ; return $ collapsed_string ; } else { return $ this -> string ; } }
Given a string, collapses any repetition at the start of the string into a single instance of the given string.
If the given string does not exist at the start of the string, returns an unmodified string.

For example, if the StringHelper was constructed with "ffoo", StringHelper::collapseStartingRepetition("f") will
return "foo". If the StringHelper was constructed with "foo", StringHelper::collapseStartingRepetition("b") will
also return "foo".

@param string $string    A string the string may or may not start with, with or without repetition

@return string           Returns a potentially modified string with a repeating, starting string collapsed into
a single instance of the string
Given a string collapses any repetition at the start of the string into a single instance of the given string . If the given string does not exist at the start of the string returns an unmodified string .