60 if ( $this->hash === null ) {
61 $this->hash = [ 0 => [], 1 => [] ];
62 foreach ( $this->names as $name ) {
63 $magic = $this->factory->get( $name );
64 $case = intval( $magic->isCaseSensitive() );
65 foreach ( $magic->getSynonyms() as $syn ) {
67 $syn = $this->factory->getContentLanguage()->lc( $syn );
69 $this->hash[$case][$syn] = $name;
87 public function getBaseRegex(
bool $capture =
true,
string $delimiter =
'/' ): array {
88 if ( $capture && $delimiter ===
'/' && $this->baseRegex !== null ) {
89 return $this->baseRegex;
91 $regex = [ 0 => [], 1 => [] ];
92 foreach ( $this->names as $name ) {
93 $magic = $this->factory->get( $name );
94 $case = $magic->isCaseSensitive() ? 1 : 0;
96 foreach ( $magic->getSynonyms() as $syn ) {
97 $quotedSynonyms[] = preg_quote( $syn, $delimiter );
99 $quotedSynonyms = implode(
'|', $quotedSynonyms );
101 if ( substr_count( $quotedSynonyms,
'\$1' ) > 1 ) {
104 $quotedSynonyms =
"(?|$quotedSynonyms)";
107 $quotedSynonyms =
"(?P<_$name>$quotedSynonyms)";
109 $regex[$case][] = $quotedSynonyms;
111 '@phan-var array<int,string[]> $regex';
112 foreach ( $regex as $case => &$re ) {
113 $re = count( $re ) ? implode(
'|', $re ) :
'(?!)';
118 '@phan-var array<int,string> $regex';
120 if ( $capture && $delimiter ===
'/' ) {
121 $this->baseRegex = $regex;
266 $regexes = $this->getRegex();
267 $res = preg_replace_callback( $regexes,
function ( $m ) use ( &$found, $returnAlias ) {
268 [ $name, $alias, $param ] = $this->parseMatch( $m );
269 $found[$name] = $returnAlias ? $alias : $param;
273 if ( $res !==
null ) {
290 $regexes = $this->getRegexStart();
291 foreach ( $regexes as $regex ) {
292 if ( preg_match( $regex, $text, $m ) ) {
293 [ $id, ] = $this->parseMatch( $m );
294 if ( strlen( $m[0] ) >= strlen( $text ) ) {
297 $text = substr( $text, strlen( $m[0] ) );