I am trying to remove some html from my string of text which comes from a WordPress generated database.
I want this:
Marnie Stanton led us through the process first and then everyone went crazy.
One of the work stations
The group is getting some great results
You can see the prints multiplying
to turn into this:
Marnie Stanton led us through the process first and then everyone went crazy.
So what I want is everything from the first to the very last
to be removed.
I have started with this:
([captions+?[^]]+])
Which only removes the first tag.
You may want to use something like this
Output:
Explanation:
is
:i
means match case insensitive,s
means match new lines with dots.
s*
: match white spaces 0 or more times[caption
: match[caption
[^]]*
: match anything except]
0 or more times]
: match]
.*?[/caption]
: match anything until[/caption]
found (and match[/caption]
)s*
: match white spaces 0 or more timesOnline demo
As it seems you just want the start of the string, I would not use a regular expression but string functions:
[caption] is an example of a shortcode. You can remove all shortcodes with WordPress’
strip_shortcodes();
function.This will output:
[caption] documentation
strip_shortcodes documentation
It seems like you can explode the string by newlines, and just take the first line…