Can it be used as a separator in preg_replace?

I am converting the eregi_replace function that I found for preg_replace, but the eregi line has just about every character on the keyboard. So I tried to use £ as a delimiter .. and it works now, but I wonder if this could potentially cause problems because it is a non-standard character?

Here is the eregi:

function makeLinks($text) {  
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);

    return $text;}

and preg:

function makeLinks($text) {
    $text = preg_replace('£(((f|ht){1}tp://)[-a-zA-^Z0-9@:%_\+.~#?&//=]+)£i',
    '<a href="\\1">\\1</a>', $text);
    $text = preg_replace('£([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)£i',
    '\\1<a href="http://\\2">\\2</a>', $text);

        return $text;
}
+3
source share
5 answers

£ , ASCII. -1 , PHP script 8- . UTF-8, £ . PCRE PHP . ( , .)

+2

, , , :

preg_replace('(abc/def#ghi)i', ...);

, , , , .

+3

@Chris, , . , '<<>' , '<<>>' . (), [], {} <>, ; , escape-, (?>...) ( ) (?<=...) (lookbehind).

@Brad : - , ?

+2

You know that data is processed better than we do. Regarding regular expression, it is no different from any other ASCII value.

Although I have to ask: what is wrong with the traditional, and then just run away? Or using a class with a range of characters?

+1
source

You can use the Unicode character to be sure.

\u00A3

Watch out for ereg features and Unicode support.

http://www.regular-expressions.info/php.html
http://www.regular-expressions.info/characters.html

Long live the queen.

+1
source

Source: https://habr.com/ru/post/1796564/


All Articles