Regular Expression Meta-character Non-digit "D"
What is regular expression meta-character Non-digit "D"?
Explanation
In Regular Expressions, the meta-character "D" is used to match any non digit character.
PHP Example:
<?php
$name = "empno-1234";
if (preg_match("/D{5}(-d{4})?$/", $name))
echo "Regex Pattern matches!";
else
echo "Regex Pattern not matched!";
?>
Result :
Pattern matches!
In the above example the pattern "/D{5}(-d{4})?$/", the first part of the pattern "D{5}" matches a string with exactly "5" characters, and in the sub pattern "(-d{4})?$" which has a "?" at end which means may or may not occur, and the pattern can be with a "-" and followed by exactly "4" digits.
Perl Example:
#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$name= "Total 5008971";
if ($name =~ m/D{5}(d{1,6})?$/)
{print "It's matched!";}
else
{print "It's not matched!";}
Result :
It's not matched!
In the above example the pattern "/D{5}(d{1,6})?$/" first part of the pattern matches exactly "5" non digit characters, and the sub pattern may or may not occur since "?" is used, the pattern specifies a digit character with 1 to 6 characters.