R
R
rinaz222020-02-19 18:44:51
JavaScript
rinaz22, 2020-02-19 18:44:51

Why doesn't reg. expression?

Hello! Wrote this regex:

preg_match_all("/(http\:\/\/|https\:\/\/|\/\/|http\:\\\/\\\/|https\:\\\/\\\/)[0-9A-z\.\/_-]+\.(?:jp(?:e?g|e|2)|gif|png|tiff?|bmp|css|js|EOT|TTF|OTF|CFF|AFM|LWFN|FFIL|FON|PFM|PFB|WOFF|SVG|STD|PRO|XSF)+/i", $text, $arr);

It should look for all links in the file with the right formats.
Everything works fine in regex101, but not in php.
https://regex101.com/r/Wwj9W6/1
When I checked with preg_last_error(), I got an error PREG_INTERNAL_ERROR
Tried to change pcre.recursion_limit in php.ini file
But nothing helped. What could be causing the error?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Gene Hagmt, 2019-06-21
@fapchat

The loop will go through 4 iterations. On the fourth, it will print "Bubblegum contains bubble gum" to the console. Before the fifth iteration, the test i < hasBubbleGum.length (4 < 4) will return false and the loop body will not be executed.

S
Stalker_RED, 2019-06-21
@Stalker_RED

THAT hasBubbleGum[i] will be indefined if i = 4 (or not?))
only then I will not become equal to four, because
a with 4<4the condition is no longer satisfied.

A
AUser0, 2020-02-19
@rinaz22

More like this then:

preg_match_all("@(https?:(?://|\\\\/\\\\/)[0-9A-z.\\\\/_-]+?\.(?:jp(?:e?g|e|2)|gif|png|tiff?|bmp|css|js|EOT|TTF|OTF|CFF|AFM|LWFN|FFIL|FON|PFM|PFB|WOFF|SVG|STD|PRO|XSF))@i", $text, $arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question