|
|
alpha Character Class in Regular expression
|
Tutorials

Regular-expression

|
Topic |
What is [[:alpha:]] Character Class in regex?
|
|
Explanation |
|
This character class represents only alphabetic characters that is from [a-zA-Z] in regular expression.
PHP Example:
<?php
$str = '1213AAA4232';
$rslt = ereg_replace("[[:alpha:]]","X",$str);
echo $rslt;
?>
Result:
1213XXX4232
In the above example for regex the character class "[[:alpha:]]" is used along with "$" to match the string at the
end for alphabetical characters alone, since its matched it returns "1".
Perl Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$str = "3333";
if ( $str =~ /[[:alpha:]]|[[:alnum:]]/)
{print "Matches!";}
else
{print "No Match!";}
Result:
Matches!
In the above example for regex the string has all numeric characters, in the pattern we use the "OR" or "|" operator
with two character classes [[:alpha:]], [[:alnum:]] so that either an alphabhet or a number is matched, so for the above
string [[:alnum:]] matches.
|
| A Note |
Simple Regex Regular Expression Tutorial Online. We welcome your Valuable feedbacks or suggestions. This is a copyright content.
|
|
|
|