priti Posted October 8, 2012 Share Posted October 8, 2012 (edited) Hi All, I have a piece of code from php.net if (!ctype_alnum($username) || !preg_match('/^(?:[a-z0-9_-]|\.(?!\.))+$/iD', $userfile)) { die("Bad username/filename"); } I do not understand "/D" ! I know of /g, /i OR /m for multi line.. can someone please help me understanding this expression. Edited October 8, 2012 by priti Quote Link to comment https://forums.phpfreaks.com/topic/269214-understanding-regular-expression/ Share on other sites More sharing options...
requinix Posted October 8, 2012 Share Posted October 8, 2012 Pattern Modifiers Quote Link to comment https://forums.phpfreaks.com/topic/269214-understanding-regular-expression/#findComment-1383637 Share on other sites More sharing options...
priti Posted October 8, 2012 Author Share Posted October 8, 2012 Pattern Modifiers Thanks for /D .Can you please also help me understanding the regular expression preg_match('/^(?:[a-z0-9_-]|\.(?!\.))+$/iD Quote Link to comment https://forums.phpfreaks.com/topic/269214-understanding-regular-expression/#findComment-1383639 Share on other sites More sharing options...
requinix Posted October 8, 2012 Share Posted October 8, 2012 (edited) Flags aside, " ^ beginning of the string (sometimes line) (?:...) group but don't capture [a-z0-9_-] letters (including uppercase since you have /i), numbers, underscores, and hyphens | or ('x|y' means 'x or y') \. literal period (?!...) negative lookahead ('the following must not be ...') + one or more of the previous, which in this case applies to the first group Summed up, the expression matches any sequence of letters/numbers/underscores/hyphens/periods but won't allow two (or more) consecutive periods. Edited October 8, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/269214-understanding-regular-expression/#findComment-1383643 Share on other sites More sharing options...
Christian F. Posted October 8, 2012 Share Posted October 8, 2012 Also, using both ctype_alnum () and preg_match () is not necessary at all. The Regular Expression alone is enough. In fact, the Regular Expression will never have any meaning in the code you posted, as the first command is way more restrictive. Since a period is not a part of the "alpha numerical" definition, the RegExp will never have the chance to test for periods. Quote Link to comment https://forums.phpfreaks.com/topic/269214-understanding-regular-expression/#findComment-1383808 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.