I want the script to continue finding the first five pieces of content after title:' and place them in variables (var1, var2, etc.); any way to get the script to repeat? Any help or insight is very much appreciated, thanks!
I'm not a regex guru, but I'll try to shed some light one these modern hieroglyphs.
In PHP, regular expressions are enclosed in a pair of slashes.
The "/i" modifier means that the engine will perform a case-insensitive match.
"title" stands for the keyword "title" you were searching for.
"( )?" will match if there is either no space or a single space.
"[^']*" will match as long as the engine hasn't reached a quotation mark since the caret symbol will basically negate the meaning of an expression enclosed in square brackets and the asterisk stands for "none or more".
The final dot will match any character (wildcard).
So, all together, this expression can be translated to : "match anything that starts with "title", is followed by 0 or 1 space, followed by a colon symbol (":"), followed by 0 or 1 space, followed by a quotation mark (') and then match as many characters as you want (this specific expression wouldn't match line breaks) until you reach another quotation mark (since this will exclude the final quotation mark, we include it in the match by using the wildcard "." at the end).
The second part of the code explodes the string where the quotation marks are to recover what was between them.
While it's possible, you wouldn't want to use such a regex to match any tag in an XML feed.