buraisu Posted November 22, 2006 Share Posted November 22, 2006 [code]preg_split('/%\w+\^|, |\$\'?|\^|\?\s*(;|%)|=|\s{5,}|\s+\?/', $string);[/code]Would someone be able to tell me exactly what all the \^|\ and such means?I know what the preg_split function does, but I dont know what all the other stuff means?Thanks Link to comment https://forums.phpfreaks.com/topic/28137-can-someone-tell-me-what-this-means/ Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 preg_split('/%\w+\^|, |\$\'?|\^|\?\s*(;|%)|=|\s{5,}|\s+\?/', $string);[b]|[/b] = this means, match the pattern that comes before it, or after it (think of it as grouping many patterns)So you have 8 patterns the regex is looking to match in the current string...[code]%\w+\^[/code]try to match a substring that starts with [b]%[/b] and is followed by any amount characters containing [b][a-zA-Z_0-9][/b] and ends with [b]^[/b], [b]\^[/b] is escaped so it part of the regex pattern. If [b]^[/b] was not escaped it would match a [b]new line[/b], but only if the [b]m[/b] modifier was used.[code], [/code]try to match a substring that starts with [b],[/b] and is followed by a single [b]space[/b][code]\$\'?[/code]try to match a substring that starts with [b]$[/b] and is [b]might be[/b] followed by a single [b]'[/b], the [b]?[/b] follows [b]'[/b], so if [b]'[/b] follows [b]$[/b] the match was made, but still, if we find [b]$[/b] and [b]'[/b] [b]doesn't[/b] follow it, we still found a match with is [b]$[/b][code]\^[/code]try to match a substring that is exactly [b]^[/b], [b]\^[/b] is escaped so it part of the regex pattern. If [b]^[/b] was not escaped it would match a [b]new line[/b], but only if the [b]m[/b] modifier was used.[code]\?\s*(;|%)[/code]try to match a substring that starts with [b]?[/b], [b]\?[/b] is escaped so it part of the regex pattern. If [b]?[/b] was not escaped it would match the preceding character 0 or 1 time. After matching [b]?[/b], match any white space character [b][ \r\n\f\t][/b] [b]one[/b] or more times. The [b]*[/b], means 1 or more times, if it was [b]+[/b] it would be 0 or more times. That is followed by a grouped condition, which means match (this|or this) as the ending of that regex pattern.[code]=[/code]try to match a substring that is exactly [b]=[/b].[code]\s{5,}[/code]try to match a substring that has a range of characters containing [b][ \r\n\f\t][/b], curly brackets are used, so this tells you that the pattern preceding must match the [b]{minimum, maximum}[/b] restriction that this pattern is controlled by. Which in this case states, that there must be at least [b]5[/b] of the following characters [b][ \r\n\f\t][/b] found one after another. Because there is no [b]maximum range[/b] set, match as many as you can greater than or equally to [b]5[/b][code]\s+\?[/code]try to match a substring that starts with any of these characters [b][ \r\n\f\t][/b], [b]+[/b], match the preceding 0 or more times, that must be followed by a [b]?[/b], to end the regex pattern. If [b]?[/b] was not escaped it would match the preceding character 0 or 1 time.printf Link to comment https://forums.phpfreaks.com/topic/28137-can-someone-tell-me-what-this-means/#findComment-129570 Share on other sites More sharing options...
Nicklas Posted November 24, 2006 Share Posted November 24, 2006 [quote author=buraisu link=topic=115937.msg472155#msg472155 date=1164218267]Would someone be able to tell me exactly what all the \^|\ and such means?[/quote]Read the manual: http://www.php.net/manual/en/reference.pcre.pattern.syntax.php Link to comment https://forums.phpfreaks.com/topic/28137-can-someone-tell-me-what-this-means/#findComment-129616 Share on other sites More sharing options...
corbin Posted November 26, 2006 Share Posted November 26, 2006 @printf: Wow regexp hacks! Link to comment https://forums.phpfreaks.com/topic/28137-can-someone-tell-me-what-this-means/#findComment-130394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.