Regular Expression





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Regex Topics
Introduction Introduction
Common Metacharacter Common Metacharacter's
Metacharacters Metacharacter's
Qualifiers Quantifier's
Word Boundry Word Boundry
Non-word Boundry Non-word Boundry
POSIX Character Classes POSIX-Character Classes
Feedback Feedback
Forums Ask Your Doubts
 




Regular Expression Meta-character Non-digit "\D"


Tutorials Regular-expression

Topic

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:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $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.





A Note

Simple Regex Regular Expression Tutorial Online. We welcome your Valuable feedbacks or suggestions. This is a copyright content.


Other Links

web hosting