PHP中的正则表达式,在[img]之间隔离
我想将内容隔离在以下两种情况之间:PHP中的正则表达式,在[img]之间隔离,php,regex,Php,Regex,我想将内容隔离在以下两种情况之间: [img]https://URL.com[/img] 或 或 所以我得到了 我试过: preg_match('/\[img[^>+](.+?)\[\/img\]', $data['body'], $titlematches); 及 但是它没有得到想要的输出。我对php一无所知,但是正则表达式应该是: \[img.*?\](.+?)\[\/img\] 希望这能帮到你 正则表达式:\[img[^\]*\]\K(?:https?:\/\/)?(?:www
[img]https://URL.com[/img]
或
或
所以我得到了
我试过:
preg_match('/\[img[^>+](.+?)\[\/img\]', $data['body'], $titlematches);
及
但是它没有得到想要的输出。我对php一无所知,但是正则表达式应该是:
\[img.*?\](.+?)\[\/img\]
希望这能帮到你 正则表达式:
\[img[^\]*\]\K(?:https?:\/\/)?(?:www\)?[a-zA-Z0-9]+\.[a-z]+
1.\[img[^\]*\]\K
这将匹配[img
直到]
然后\K
重置匹配
2.(?:https?:\/\/)(?:www\)?[a-zA-Z0-9]+\.[a-z]+
这将匹配您的url
PHP代码:
<?php
ini_set('display_errors', 1);
$string='
[img]https://URL.com[/img]
[img width=100]https://URL.com[/img]
[img *whatever*]https://URL.com[/img]';
preg_match_all('/\[img[^\]]*\]\K(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9]+\.[a-z]+/', $string,$matches);
print_r($matches);
希望这能帮到你。。。
preg_match('/\[img](.+?)\[\/img\]/i', $data['body'], $titlematches);
\[img.*?\](.+?)\[\/img\]
<?php
ini_set('display_errors', 1);
$string='
[img]https://URL.com[/img]
[img width=100]https://URL.com[/img]
[img *whatever*]https://URL.com[/img]';
preg_match_all('/\[img[^\]]*\]\K(?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9]+\.[a-z]+/', $string,$matches);
print_r($matches);