Friday, November 30, 2018

php - Match regex pattern that isn't within a bbcode tag

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...