Vidya_tr Posted April 1, 2009 Share Posted April 1, 2009 what do the tags such as \s , \w , \d etc indicate in preg_replace?? I am not able to get this... <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?> Also please tell me how does the delimiter parenthesis work in preg_replace... Quote Link to comment https://forums.phpfreaks.com/topic/152024-solved-using-preg_replace/ Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 Straight from DarkWater's regex tutorial: /\d/ #matches any digit /\D/ #matches any NON-DIGIT /\w/ #matches any word character (which includes the underscore and digits, so it's like [a-zA-Z0-9_]) /\W/ #matches any NON-WORD character /\s/ #matches any whitespace character like a literal space, a tab, and a newline /\S/ #matches any NON-WHITESPACE character Quote Link to comment https://forums.phpfreaks.com/topic/152024-solved-using-preg_replace/#findComment-798383 Share on other sites More sharing options...
Vidya_tr Posted April 1, 2009 Author Share Posted April 1, 2009 thank you... the tutorial DarkWater's regex tutorial found very useful for me to learn about the metacharacters and the way they are used in preg_replace and preg_match. Quote Link to comment https://forums.phpfreaks.com/topic/152024-solved-using-preg_replace/#findComment-798410 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.