【发布时间】:2023-01-12 10:14:41
【问题描述】:
我有一个像这样的字符串:
@test hello how are you @abcdef
我将如何自动制作它以便将所有具有 @ 的文本转换为类似以下内容:
https://example.com/test
https://example.com/abcdef
我试过使用 regex 和 preg_replace 但无法完美地完成它。
【问题讨论】:
标签: php regex preg-replace
我有一个像这样的字符串:
@test hello how are you @abcdef
我将如何自动制作它以便将所有具有 @ 的文本转换为类似以下内容:
https://example.com/test
https://example.com/abcdef
我试过使用 regex 和 preg_replace 但无法完美地完成它。
【问题讨论】:
标签: php regex preg-replace
尝试将正则表达式 @(S+) 替换为 https://example.com/$1:
$string = '@test hello how are you @abcdef';
$result = preg_replace('/@(S+)/', 'https://example.com/$1', $string);
print($result);
【讨论】:
@(w+)(?:<[^<>]*>)?之类的东西