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
 




alnum Character Class in Regular expression


Tutorials Regular-expression

Topic

What is [[:alnum:]] Character Class in regex?




Explanation

The [[:alnum:]] character class represents alphabetic and numeric characters, and it is same as using [a-zA-Z0-9] in regular expression.

PHP Example:
    <?php
    $org = 'AAA**&18';
    $det = ereg_replace("[[:alnum:]]","@",$org);
    echo $det;
    ?>
Result:
    @@@**&@@

In the above regex example the character class "[[:alnum:]]" is used along with the metacharacter "^",which specifies to match the begining of the string, since the string has the number "1" in the beginning its matched.

Perl Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $str = "wew436*3631";
    if ( $str =~ /[^[:alnum:]]/ ) 
      {print "Character other than alphanumeric!";} 
    else 
      {print "Only alphanumeric characters!";}
Result:
    Character other than alphanumeric!

In the above example the metacharacter "^" refers the begining of the string, but here its used like "/[^[:alnum:]]/" which means "NOT" a alphanumeric character. Since the string has a "*" it matches as it not a alphanumeric character.




A Note

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


Other Links

web hosting