I am attempting to create a regex patten that will match words in a string that begin with @
Regex that solves this initial problem is '~(@\w+)~'
A second requirement of the code is that it must also ignore any matches that occur within [quote]
and [/quote]
tags
A couple of attempts that have failed are:
(?:[0-9]+|~(@\w+)~)(?![0-9a-z]*\[\/[a-z]+\])
/[quote[\s\]][\s\S]*?\/quote](*SKIP)(*F)|~(@\w+)~/i
Example: the following string should have an array output as displayed:
$results = [];
$string = "@friends @john [quote]@and @jane[/quote] @doe";
//run regex match
preg_match_all('regex', $string, $results);
//dump results
var_dump($results[1]);
//results: array consisting of:
[1]=>"@friends"
[2]=>"@john"
[3]=>"@doe
No comments:
Post a Comment