Jump to content

Recommended Posts

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...

 

 

Link to comment
https://forums.phpfreaks.com/topic/152024-solved-using-preg_replace/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.