L
L
lodbrock2020-05-17 15:08:35
Regular Expressions
lodbrock, 2020-05-17 15:08:35

How to find all characters in string "abaabaaabaabaaaa" except substring "aa"?

Hello. Suppose there is a string "abaabaaabaabaaaa", how to find all the characters in it, except for the substring "aa"?
The result should be " ab aa baaab aa baaaa ".
I managed to do the opposite. Find an occurrence of "aa" regex101 .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-05-17
@lodbrock

$str = 'abaabaaabaabaaaa';
$out = preg_split('~(?<!a)aa(?!a)~', $str, -1, PREG_SPLIT_NO_EMPTY);
print_r($out);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question