3

this is probably not a task, but a question, now I'll explain what I want to ask.

So, backstory, there are the following input data:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
[ABCDEFGHIJKLMNO] incididunt ut labore et dolore magna aliqua. Ut enim ad minimus veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure http://domains.ua/ dolor in reprehenderit in voluptate velit esse cillum
dolore eu: fugiat: nulla pariatur. Excepteur sint occaecat: cupidatat [non] proident :,
sunt in culpa qui officia deserunt mollit anim id est labor labor. https://foo.co.uk/ *end.

The task was to find all occurrences that are in square brackets, in this line: this is: [ABCDEFGHIJKLMNO] and [non], then find all the links that begin with http/https and end with slash (/) followed by a space immediately. (correctness of references is not important)

In general, to find all these occurrences was easily, here is the regular expression (demo):

\[.*?\]|https?://[\w\.]+/\h

Is it possible to invert this regular expression so as to find everything except the conditions specified in the task? (do not highlight in square brackets and links)

wnull
  • 217
  • 6
  • 21

1 Answers1

0

Many thanks for the help @WiktorStribiżew, think, i solved the issue the following way:

echo join('', preg_split('~\[.*?]|https?://[\w.]+/\h~', $string));
wnull
  • 217
  • 6
  • 21