WorldDrknss Posted June 29, 2007 Share Posted June 29, 2007 I am fairly new to regex and need some help deciphering the following: eregi("<[^>]*script*\"?[^>]*>", $check_url) If I am correct this will check the url for: find a: < find any string containing zero or more: > at the beginning of the line find any string containing zero or more: script find any string containing zero or one: " find any string containing zero or more: > at the beginning of the line find a: > Quote Link to comment Share on other sites More sharing options...
effigy Posted June 29, 2007 Share Posted June 29, 2007 The regular expression: (?-imsx:<[^>]*script*"?[^>]*>) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- < '<' ---------------------------------------------------------------------- [^>]* any character except: '>' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- scrip 'scrip' ---------------------------------------------------------------------- t* 't' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- "? '"' (optional (matching the most amount possible)) ---------------------------------------------------------------------- [^>]* any character except: '>' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- > '>' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted June 29, 2007 Author Share Posted June 29, 2007 So ^ only indicates at the beginning of the line if it is first within the regex and is used as a wild character within brackets. Quote Link to comment Share on other sites More sharing options...
effigy Posted June 29, 2007 Share Posted June 29, 2007 Metacharacters differ inside and outside of a character class. ^ as the first character in a character class negates the class; it's a literal anywhere else in the class or outside of it. Quote Link to comment Share on other sites More sharing options...
WorldDrknss Posted June 29, 2007 Author Share Posted June 29, 2007 Ok, thanks for your help. Quote Link to comment Share on other sites More sharing options...
effigy Posted July 2, 2007 Share Posted July 2, 2007 Slight correction: Outside of a character class the caret is a BOL (beginning of line) anchor unless it is escaped. 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.