Jump to content

Can someone tell me what this means?


buraisu

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.