![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with grep and regex | raichlea | UNIX for Dummies Questions & Answers | 14 | 04-16-2008 08:25 AM |
| regex in variable | alias47 | UNIX for Dummies Questions & Answers | 4 | 08-08-2007 05:37 AM |
| regex question | xiamin | Shell Programming and Scripting | 2 | 07-16-2007 04:40 AM |
| Regex?? Please help | lunac | UNIX for Dummies Questions & Answers | 7 | 01-30-2007 10:13 AM |
| sed regex | Shakey21 | UNIX for Dummies Questions & Answers | 4 | 01-31-2002 06:16 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Regex
Hi,
i want to match a string using perl that has got 5 pluses(+++++). i am using a function for this. $str1="+++++"; check($str1,"\\+"); sub check{ $str1=$_[0]; $str2=$_[1]; if($str1=~m/^$str2{5}$/){ print "Correct.\n"; }else{ print "Wrong..\n"; } } But i am getting the output as wrong. if i use if($str1=~m/^\+{5}$/) this i will get correct output. Please help me. Thanks, Deepak |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code is working fine.
Code:
$ cat spt
#!/usr/bin/perl
$str1="+++++";
check($str1,"\\+");
sub check{
$str1=$_[0];
$str2=$_[1];
if($str1=~m/^$str2{5}$/){
print "Correct.\n";
}else{
print "Wrong..\n";
}
}
$ ./spt
Correct.
|
|
#3
|
|||
|
|||
|
ya this is working fine.
but if i change the code like using another variable $no. #!/usr/bin/perl $str1="+++++"; $no=5; check($str1,"\\+",$no); sub check{ $str1=$_[0]; $str2=$_[1]; $str3=$_[2]; if($str1=~m/^$str2{$str3}$/){ print "Correct.\n"; }else{ print "Wrong..\n"; } } perl test1.pl Wrong.. Help me please... Thanks, Deepak |
|
#4
|
|||
|
|||
|
Code:
#!/usr/bin/perl
$str1="+++++";
$no=5;
check($str1,"\\+",$no);
sub check{
$str1=$_[0];
$str2=$_[1]."\{".$_[2]."\}";
if($str1=~m/^$str2$/){
print "Correct.\n";
}else{
print "Wrong..\n";
}
}
|
|
#5
|
|||
|
|||
|
Quote:
Without that it would work !!! Code:
#! /opt/third-party/bin/perl
sub check {
$first = $_[0];
$character = $_[1] . "{" . $_[2] . "}";
print "yes\n" if( $first =~ m/^$character$/ );
}
$str = "+++++";
$no = 5;
check($str, "\\+", $no);
exit 0
|
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
|||
|
|||
|
how about this
do_something if m/[+]{5}/ |
|||
| Google The UNIX and Linux Forums |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|