Hi I Am Timbo Posted March 28, 2007 Share Posted March 28, 2007 I have a regular expression and I am reading tutorials on it, but it is really taking me a long time to figure out what this does: /^([^\s]+)\s+(.+)\s+(.*\d+)\s+([^\s\d]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+(.*[^\s]+)\s+([^\s]+)$/ If someone could help me, that would be great. I'm trying to break it down, but I don't understand it all. What is \s? Quote Link to comment Share on other sites More sharing options...
effigy Posted March 28, 2007 Share Posted March 28, 2007 Here's some help; see these resources for more information. / ### Starting delimiter ^ ### BOL (Beginning of Line) ([^\s]+) ### Capture one or more instances of non-whitespace; this is better written as (\S+) \s+ ### One or more instances of whitespace. (.+) ### One or more instances of any character excluding a new line. \s+ (.*\d+) ### Capture zero or more instances of any character excluding a new line, followed by one or more digits. \s+ ([^\s\d]+) \s+ ([^\s]+) \s+ ([^\s]+) \s+ ([^\s]+) \s+ (.*[^\s]+) \s+ ([^\s]+) $ ### Match at EOL or before a new line. / ### Ending delimiter Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted March 28, 2007 Author Share Posted March 28, 2007 That really helps a lot. Let me see if I can get the rest of this down then: / ### Starting delimiter ^ ### BOL (Beginning of Line) ([^\s]+) ### Capture one or more instances of non-whitespace; this is better written as (\S+) \s+ ### One or more instances of whitespace. (.+) ### One or more instances of any character excluding a new line. \s+ (.*\d+) ### Capture zero or more instances of any character excluding a new line, followed by one or more digits. \s+ ([^\s\d]+) ### Capture one or more instances of non-whitespace, followed by one or more digits \s+ ([^\s]+) \s+ ([^\s]+) \s+ ([^\s]+) \s+ (.*[^\s]+) ### Capture zero or more instances of any character excluding a new line, followed by one or more instances of non-whitespace; this is better written as (\S+) \s+ ([^\s]+) $ ### Match at EOL or before a new line. / ### Ending delimiter If I put that in preg_match($regex, $token, $array); it will do this if it is matched: $array[] = $token; Is that correct? Quote Link to comment Share on other sites More sharing options...
effigy Posted March 28, 2007 Share Posted March 28, 2007 Almost. The entire match comes first, followed by any captured ones. If you want to keep the comments, you'll have to remove the last one after the ending delimiter and add the proper modifier. Something like this: $regex = '/ pattern and comments here /x'; Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted March 28, 2007 Author Share Posted March 28, 2007 Almost. The entire match comes first, followed by any captured ones. I guess I don't know what you mean by this. Does this mean that the array would look like $array[0] = $token; $array[1] = first part of $token; $array[2] = second part of token;??? Quote Link to comment Share on other sites More sharing options...
effigy Posted March 28, 2007 Share Posted March 28, 2007 See the bottom of this example. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.