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: > Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/ 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 ---------------------------------------------------------------------- Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/#findComment-285822 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. Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/#findComment-286071 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. Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/#findComment-286076 Share on other sites More sharing options...
WorldDrknss Posted June 29, 2007 Author Share Posted June 29, 2007 Ok, thanks for your help. Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/#findComment-286078 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. Link to comment https://forums.phpfreaks.com/topic/57677-solved-quick-explanation/#findComment-288015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.