The14thGOD Posted August 24, 2009 Share Posted August 24, 2009 More confusion to the confusing regex =P I want to match all non alpha-numeric and hyphens, i read this does it: <?php $string = preg_replace('/[^a-zA-Z0-9-]/','',$string);?> Why does this do it? is it cause of the ^ in the brackets? I thought that was used as the starting point of the string (but I also havn't seen it inside the brackets, i think it's normally outside?). So is ^ inside [] == ! ? Thanks! Justin Quote Link to comment https://forums.phpfreaks.com/topic/171680-solved-regex-match-all-that-dont-match-expresion/ Share on other sites More sharing options...
nrg_alpha Posted August 24, 2009 Share Posted August 24, 2009 That pattern looks correct.. When dealign with ^, if it is at the very start of the pattern, this means start matching something at the beginning of the string.. but if it is the very first character in a character class like so: [^ ... ], it makes the character class negative.. so it will match (or replace in this case) any characters that are not within the class. Quote Link to comment https://forums.phpfreaks.com/topic/171680-solved-regex-match-all-that-dont-match-expresion/#findComment-905267 Share on other sites More sharing options...
The14thGOD Posted August 24, 2009 Author Share Posted August 24, 2009 thx! Quote Link to comment https://forums.phpfreaks.com/topic/171680-solved-regex-match-all-that-dont-match-expresion/#findComment-905272 Share on other sites More sharing options...
nrg_alpha Posted August 24, 2009 Share Posted August 24, 2009 You can read up about regex in these starter links: http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax http://www.regular-expressions.info/ http://weblogtoolscollection.com/regex/regex.php Quote Link to comment https://forums.phpfreaks.com/topic/171680-solved-regex-match-all-that-dont-match-expresion/#findComment-905284 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.