Hi,
Yes, they are the same.
I like to use $_ only when the data comes in $_ naturally. Like in a for loop:
for (qw< abc >)
{
if ( !/\w+\d+/ )
{
print "not matched";
}
}
Otherwise, I have to write $_, then I prefer to name the variable something
descriptive instead.
Makes the code
On 4/20/07, Rodrick Brown <[EMAIL PROTECTED]> wrote:
I'm testing a regex with the sample data
Chicago Bulls 55 66
Miami Heat 13 44
Alpha Dogs 22 48
Hornets 84 22
Celtics 22 24
while($line = )
{
$line =~ m/((\w+\s+)?\w+)\s+(\d+)\s+(\d+)/;
($team,$wins,$losses) = ($1, $3, $4);
print $
Paul Beckett wrote:
>
> I would like to match multiple occurrences of the same pattern:
> /\'([a-z0-9]{32})\'/
> This could appear 0 - to many times on a line.
> I need the actual text match, not just the occurrence frequency.
> Any suggestions as to how I could catch these would be appreciated.
[EMAIL PROTECTED] wrote:
> Hi,
Hello,
> if ($_ =~ m/match string/i) {
> if ($_ =~ m/does not match string/i) {
> } else {
> print $_;
According to that logic:
$ perl -le'
for ( "abcdefgh", "rstuvwxyz", "jklmnop", "abcdefwxyz" ) {
if ( /cde/i ) {
if ( !/xyz/i ) {
} else
On Wed, 2006-31-05 at 12:03 +0200, [EMAIL PROTECTED] wrote:
> Hi,
>
> if ($_ =~ m/match string/i) {
> if ($_ =~ m/does not match string/i) {
> } else {
> print $_;
>
> Regex is not my strong point, so I'm going to ask... Is there any way to
> write
> that better? Preferably onl
if (($_ =~ m/match string/i) && ($_ !~ m/does not match string/i)) {
Works flawlessly, thanks allot...
--
Chris
Quoting Shashidhara Bapat <[EMAIL PROTECTED]>:
> Hi,
>
> yes you can do that. For "not match", you got to use "!~".
>
> - shashi
>
> On 5/31/06, [EMAIL PROTECTED] <[EMAIL PROTECT
On 4/18/06, Jenda Krynicky <[EMAIL PROTECTED]> wrote:
> From: "Jay Savage" <[EMAIL PROTECTED]>
> > On 4/14/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > > Timothy Johnson wrote:
> > > > Will the string always have the two quotes in the same place and
> > > > only one per string? W
Jay Savage wrote:
> On 4/14/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:
>>
>>Timothy Johnson wrote:
>>>Will the string always have the two quotes in the same place and only
>>>one per string? What about something like this?
>>>
>>>/.*?\{([^\}]*)\}(?=.*")/gi
>>I tested it out and it appears to b
Timothy Johnson schreef:
> /.*?\{([^\}]*)\}(?=.*")/gi
There is no need to escape a } in a character class.
Something like
[^x]*x
can also be written as
.*?x
The "/i" modifier is superfluous. The last .* can also be minimalized.
So an alternative is:
/ [{] (.*?) [}] (?=.*?") /xg
Jay Savage wrote:
On 4/14/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:
Timothy Johnson wrote:
Will the string always have the two quotes in the same place and only
one per string? What about something like this?
/.*?\{([^\}]*)\}(?=.*")/gi
I tested it out and it appears to be perect!
On 4/14/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:
>
>
> Timothy Johnson wrote:
> > Will the string always have the two quotes in the same place and only
> > one per string? What about something like this?
> >
> > /.*?\{([^\}]*)\}(?=.*")/gi
>
> I tested it out and it appears to be perect! Than
-Original Message-
From: JupiterHost.Net [mailto:[EMAIL PROTECTED]
Sent: Friday, April 14, 2006 12:15 PM
To: beginners@perl.org
Subject: Re: regex matching conditionally
>Timothy Johnson wrote:
>> Will the string always have the two quotes in the same place and only
>>
Timothy Johnson wrote:
Will the string always have the two quotes in the same place and only
one per string? What about something like this?
/.*?\{([^\}]*)\}(?=.*")/gi
I tested it out and it appears to be perect! Thank Mr. Johnson :)
I love when I learn a new tidbit!
--
To unsubscribe, e-
Not what you asked for, but probably more correct:
my @matches;
use Regexp::Common;
my @quoted = ($string =~ /$RE{quoted}/g);
foreach my $quoted ( @quoted ) {
push( @matches, ($quoted =~ /$RE{balanced}{-parens=>'{}'}/g) );
}
print join "\n", @matches;
Thanks, it was the same sort of i
JupiterHost.Net wrote:
Howdy list,
I'm trying to see if I can do this in one regex instead of multiple
stage, mainly for educational purposes since I already have it in
multipel steps.
I am trygin to get each string between { and } where the {} occurs
between double quotes. So with
"file
Timothy Johnson wrote:
Will the string always have the two quotes in the same place and only
Well, it could have multiple {} inside or outside of multiple "" AFAIK.
one per string? What about something like this?
/.*?\{([^\}]*)\}(?=.*")/gi
That does work on that exact string, I'll have
Will the string always have the two quotes in the same place and only
one per string? What about something like this?
/.*?\{([^\}]*)\}(?=.*")/gi
-Original Message-
From: JupiterHost.Net [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 13, 2006 5:16 PM
To: beginners@perl.org
Subject:
Juan Manuel Casenave wrote:
> Hi,
>
> I've got a .txt with 25 of numerically named lines (example).
> (Example):
>
> 1. First Name:
> 2. Last Name:
> 3. Age:
> 4. Company:
> 5. Quality of the service:
> ...
> 25. Would you recommend our services:
>
> I'm trying to strip everything after the col
On Oct 11, Juan Manuel Casenave said:
1. First Name:
2. Last Name:
3. Age:
#!/usr/bin/perl
# strip_answers.pl
use strict;
use warnings;
# array to store the stripped results
my @information;
# open a filehandle to output.txt (where the results are stored) in read
mode
open (IN, '<', 'outpu
Jason,
You state your question, and practically give the answer in the solution.
:-)
You have a for loop inside a while loop. Both loops set $_. You state that
you can not properly do your match within the for loop because you need the
$_ value set by the while loop. Well ... why don't you just "
Ben Crane wrote:
>
> Here is a code snippet, and yes I am going to use
> File::Basename to strip the file path/filename once
> I've stripped the entire path from a string.
>
> The string $_ is a line in a text file. I want to use
> File::Basename to pull apart the file path and
> filename, but firs
Nope that was it, I just knew that we didn't have to loop through the array
to build the string :)
Thanks!
-Original Message-
From: bob ackerman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 11, 2002 1:57 PM
To: [EMAIL PROTECTED]
Subject: Re: RegEx matching multiple items.
you have something else in mind?
>
> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 11, 2002 12:48 PM
> To: Kingsbury, Michael
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: RegEx matching multiple items.
&g
Hello,
How would you put the matches into a comma separated list?
-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 11, 2002 12:48 PM
To: Kingsbury, Michael
Cc: '[EMAIL PROTECTED]'
Subject: Re: RegEx matching multipl
On Apr 11, Kingsbury, Michael said:
>
>
> -> "SPRID12345678"
>"SPRID23456789"
>
>
>I want to match the SPRID strings.
@data = $string =~ /SPRID\d+/g;
Or, if you only want the numbers:
@data = $string =~ /SPRID(\d+)/g;
This is assume $string is the ENTIRE data. Otherwis
June 14, 2001 3:54 PM
To: Evgeny Goldin (aka Genie); [EMAIL PROTECTED]
Subject: Re: regex matching
At 09:59 PM 6/14/01 +0200, Evgeny Goldin (aka Genie) wrote:
> > /(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)/;
>
> >
>
/([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\
At 09:59 PM 6/14/01 +0200, Evgeny Goldin (aka Genie) wrote:
> > /(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)/;
>
> >
> /([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
> > 4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])/)
>
>Wou ! Looks like too many symbols .. Does matching
> /(\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?)/;
> /([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
> 4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])/)
Wou ! Looks like too many symbols .. Does matching a legal IP worth
a regex 1km long ? I think it's better to match the IP
Ok, strike my previous comments.
My apologies for wasting your time.
- Original Message -
From: "Ken" <[EMAIL PROTECTED]>
To: "John Edwards" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, June 14, 2001 9:45 AM
Subject: Re: regex matchi
st for a valid IP address.
John
-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: 14 June 2001 16:46
To: John Edwards; [EMAIL PROTECTED]
Subject: Re: regex matching
Doesn't {1,3} mean minimum of 1 and maximum of 3 of whatever character comes
before the {}'s?
I
code will work just fine.
Jason
-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 11:46 AM
To: John Edwards; [EMAIL PROTECTED]
Subject: Re: regex matching
Doesn't {1,3} mean minimum of 1 and maximum of 3 of whatever character comes
;[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Thursday, June 14, 2001 9:40 AM
Subject: RE: regex matching
> "To just make sure what you have is an ip (and only an ip) is:
> m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;"
>
> Not true. An IP can
e isn't perfect (and I nicked the essentials of it from the
Perl Cookbook) but it will at least not match on completely wrong IPs.
John
-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: 14 June 2001 16:32
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: regex match
\d only matches one digithere's a way to extract each number from an ip:
use strict;
my( $ip );
print "Enter a string with an IP:";
$ip = ;
$ip =~ m/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
print "$1\n";
print "$2\n";
print "$3\n";
print "$4\n";
Or if you just want the ip from the line:
u
This will give you the IP only if valid. I've attached as a file too in case
the code gets mangled.
---
$string = "here is a sample with 123.456.123.456 in the middle.";
if ($string =~
/([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
4]\d|25[0-5])\.([01]?\d\d|2[0-4]
--- [EMAIL PROTECTED] wrote:
> i have a basic knowledge of regex but i want to know if there is a
> simpler way to pull patterns out of a line.
>
> if i have a line like:
>
> here is a sample with 123.456.123.456 in the middle.
>
> m/\d\.\d\.\d\.\d/ will match the entire line. is there a
36 matches
Mail list logo