|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | 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 and shell scripting languages here. |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
Comma in regular expression
Hi,
I need to check if string contains comma... Wrote like ~ m/\,/ but no luck... Also taken comma in variable and checked with ~ m/($comma)/ but this also doesn't help.... Please advise |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
Code:
my $var;
while(1)
{
$var=<>;
if($var=~/,/)
{
print $var;
last;
}
} |
|
#3
|
||||
|
||||
|
Hi , darshakraut your method also should work if your string is valid. Try this, Code:
if($string=~m/,/) |
|
#4
|
||||
|
||||
|
see the following regular expression. Code:
if ( $val =~ m/[,]/) [or] Code:
if ( $val =~ m%,%) you can change the delimiter instead of "/" like %, #, !, | etc., Last edited by ungalnanban; 03-16-2010 at 06:53 AM.. |
|
#5
|
||||
|
||||
|
what about with a grep if Code:
sample="hello,fool" then Code:
echo "$sample" | grep -c "," returns 1 while Code:
sample1="not here" echo "$sample1" | grep -c "," returns 0 and the result could be put to a variable. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regular Expression | siba.s.nayak | Shell Programming and Scripting | 3 | 11-12-2009 05:48 PM |
| Regular Expression | mradsus | Shell Programming and Scripting | 2 | 08-05-2008 04:29 AM |
| regular expression...help!! | andy2000 | UNIX for Dummies Questions & Answers | 6 | 07-18-2007 05:10 PM |
| awk and regular expression | maskot | Shell Programming and Scripting | 4 | 05-22-2007 07:22 AM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |