File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -119,8 +119,21 @@ public static function markString($needle, $haystack)
119119 */
120120 public static function highlightString ($ str )
121121 {
122+ /*
123+ [^←→]: matches any character but the marker characters.
124+ [^←→]|(?R): matches any character but the marker characters,
125+ or recursively the entire pattern.
126+
127+ This is wrapped in a non capturing group (?:), since we're
128+ only interested in the content of the more external markers.
129+ For example, for “←←A→dd→” we're only interested in “←A→dd”,
130+ capturing “←A→” is not useful.
131+ Internal extra markers are later removed by str_replace.
132+
133+ See also http://stackoverflow.com/a/14952740
134+ */
122135 $ str = preg_replace (
123- '/←(. *)→/isU ' ,
136+ '/←((?:[^←→]|(?R)) *)→/iu ' ,
124137 "<span class='highlight'>$1</span> " ,
125138 $ str
126139 );
Original file line number Diff line number Diff line change @@ -176,6 +176,7 @@ public function highlightStringDP()
176176 ['←Cronologia→ di navigazione ' , '<span class= \'highlight \'>Cronologia</span> di navigazione ' ],
177177 ['←servi←ce→→ ' , '<span class= \'highlight \'>service</span> ' ],
178178 ['Cronologia di navigazione ' , 'Cronologia di navigazione ' ],
179+ ['←←A→dd→ more ←se←a→rch→ ←engine→s… ' , '<span class= \'highlight \'>Add</span> more <span class= \'highlight \'>search</span> <span class= \'highlight \'>engine</span>s… ' ],
179180 ];
180181 }
181182
You can’t perform that action at this time.
0 commit comments