$ matches at end of line
. matches any single character except newline (\n)
* matches zero or more of previous character or group
? matches zero or more of previous character or group
+ matches one or more of previous character or group
.* as many characters as you like
Program to illustrate above regular expressions
#!/usr/bin/perl
#should be
while(STDIN)
{
if(/^hello/g)
{
print("hello is at the beginning \n")
}
if(/Bye$/g)
{
print("Bye is at the end \n")
}
if(/A?/g)
{
print("This has zero and one A with regular Expression'?'\n")
}
if(/A*/g)
{
print("This has zero and one A with regular Expression '*' \n")
}
if(/A+/g)
{
print("This has one or more A \n")
}
}
No comments:
Post a Comment