Jump to content

[SOLVED] need help understanding what this expression does


jake2891

Recommended Posts

The basic rundown is:

 

^ from the beginning of string

( start a new capture

[ ]+ a character class that looks to see if the current character is a space (one or more times, due to the +)

<[^>]+> followed by <, then anything that is not > (due to the [^>]) one or more times, then a >

.+ the dot is a dot_match_all wildcard character that matches anything that is not a newline by default (one or more times).

) close capture

<\/[^>]+> followed by <, then / (this slash needs to be escaped using \ before it, as the delimiters surrounding the entire pattern is the / character), then anything that is not a > (one or more times), then finally >

$ end of string.

 

So anything that is within the set of parenthesis that the pattern matches gets stored into a regex variable called $1 (which is used as the second parameter in the regex as a replacement in $str.

 

There are some bad forms with this though.. by example, if you look for a single character space (as in the space within the first character class [ ]), you don't need to encase it in a character class.. simply providing a literal space (or the hex vale \x20). Other aspects like .+ means its greedy.. match anything up to a newline. But as a result, the regex engine will now start to backtrack to accommodate what comes after that in the pattern (which can create accuracy / speed problems).

 

you can learn more about regex by viewing the following links:

 

regex tutorials

weblogtools

phpfreaks regex resources

phpfreaks regex tutorial

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.