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 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. 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! 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 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
Archived
This topic is now archived and is closed to further replies.