Re: regex needed
by moritz (Cardinal) on Jul 12, 2012 at 11:50 UTC
|
my ($before, $after) = split /\$\$/, $line, 2;
| [reply] [d/l] |
Re: regex needed
by Anonymous Monk on Jul 12, 2012 at 10:47 UTC
|
Your code doesn't show any attempts at matching , or you want what?
my( @this ) = $line =~ /$regex/gi;
my @want = ( 'DATE', '_RE_IRD_Soc' );
Test::More::is_deeply( \@this, \@want, "got what I needed");
This ought to do $regex = qr{
\$ \(
( [^\)]+ ) # $1
\)
(.*) # $2
}xmi;
Death to Dot Star! | [reply] [d/l] [select] |
Re: regex needed
by BillKSmith (Monsignor) on Jul 12, 2012 at 11:52 UTC
|
The /g option on your regular expression does not do anything useful here and can cause problems. | [reply] |
|
|
| [reply] |
Re: regex needed
by cheekuperl (Monk) on Jul 12, 2012 at 10:44 UTC
|
I need to capture anything after $$
my $line = '%TMP%\$$(DATE)_RE_IRD_Soc';
my $line2 = '%RESULTS%\$$(DATE_USA)' ;
my $line3 = '%RESULTS%\$$(1110_DATE_USA)';
@lines=($line,$line2,$line3);
foreach $elem (@lines)
{
while($elem=~m/(.*)\$\$(.*)/g)
{
print "\nBefore: [$1], After : [$2]";
}
}
I need to capture anything after $$ ,in $1 and $2.
You have not mentioned what exactly you want in $1 and $2. | [reply] [d/l] |
|
|
sorry, from $line, I need DATE in $1 and _RE_IRD_Soc in $2
$line2, $line3 doesn't have anything in $2. my idea is to have one regex which satisfy both conditions.
| [reply] |
|
|
if( $line =~ m[ \$\$ # two dollar signs
\( # open paren
([^)]+) # capture until closed paren
\) # close paren
(.*) # capture the rest, if any
]x ){
# do stuff with $1 and $2
}
Aaron B.
Available for small or large Perl jobs; see my home node.
| [reply] [d/l] |
|
|
my $line = '%TMP%\$$(DATE)_RE_IRD_Soc';
my $line2 = '%RESULTS%\$$(DATE_USA)' ;
my $line3 = '%RESULTS%\$$(1110_DATE_USA)';
@lines=($line,$line2,$line3);
foreach $elem (@lines)
{
if($elem=~m/.*\$\$(\(.*\))(.*)?/)
{
print "\nFirst: $1, Second: $2";
}
}
| [reply] [d/l] |
Re: regex needed
by monsoon (Pilgrim) on Jul 12, 2012 at 15:01 UTC
|
my (undef,$one,$two) = split /[()]/, $line;
| [reply] [d/l] |
Re: regex needed
by ckj (Chaplain) on Jul 12, 2012 at 19:02 UTC
|
my $line = '%TMP%\$$(DATE)_RE_IRD_Soc';
my $line2 = '%RESULTS%\$$(DATE_USA)' ;
my $line3 = '%RESULTS%\$$(1110_DATE_USA)';
foreach my $x ($line, $line2, $line3)
{print "lklklk";
while($x=~m/\$\$\((.*?)\)(\w*)/g)
{
print "1st Element is [$1] and second is : [$2]\n";
}
}
| [reply] [d/l] |