Re: regex matching statements

2024-06-18 Thread Levi Elias Nystad-Johansen via beginners
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

Re: Regex Matching & Grouping

2007-04-19 Thread Chas Owens
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 $

Re: regex matching multiple occurances

2006-08-02 Thread Rob Dixon
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.

Re: regex matching

2006-05-31 Thread John W. Krahn
[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

Re: regex matching

2006-05-31 Thread Mr. Shawn H. Corey
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

Re: regex matching

2006-05-31 Thread cknipe
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

Re: regex matching conditionally

2006-04-18 Thread Jay Savage
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

Re: regex matching conditionally

2006-04-15 Thread John W. Krahn
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

Re: regex matching conditionally

2006-04-15 Thread Dr.Ruud
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

Re: regex matching conditionally

2006-04-14 Thread JupiterHost.Net
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!

Re: regex matching conditionally

2006-04-14 Thread Jay Savage
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

RE: regex matching conditionally

2006-04-14 Thread Timothy Johnson
-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 >>

Re: regex matching conditionally

2006-04-14 Thread JupiterHost.Net
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-

Re: regex matching conditionally

2006-04-14 Thread JupiterHost.Net
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

Re: regex matching conditionally

2006-04-13 Thread Randy W. Sims
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

Re: regex matching conditionally

2006-04-13 Thread JupiterHost.Net
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

RE: regex matching conditionally

2006-04-13 Thread Timothy Johnson
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:

RE: Regex matching problem

2005-10-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
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

Re: Regex matching problem

2005-10-11 Thread Jeff 'japhy' Pinyan
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

Re: regex matching in a nested loop

2004-10-29 Thread Zeus Odin
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 "

Re: REGEX: matching AFTER a specific character

2003-12-19 Thread Rob Dixon
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

RE: RegEx matching multiple items.

2002-04-11 Thread Amerson, Kevin
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.

Re: RegEx matching multiple items.

2002-04-11 Thread bob ackerman
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

RE: RegEx matching multiple items.

2002-04-11 Thread Amerson, Kevin
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

Re: RegEx matching multiple items.

2002-04-11 Thread Jeff 'japhy' Pinyan
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

RE: regex matching

2001-06-14 Thread Jason C. Lamb
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]\

Re: regex matching

2001-06-14 Thread Peter Scott
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

Re: regex matching

2001-06-14 Thread Evgeny Goldin (aka Genie)
> /(\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

Re: regex matching

2001-06-14 Thread Ken
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

RE: regex matching

2001-06-14 Thread John Edwards
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

RE: regex matching

2001-06-14 Thread Jason C. Lamb
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

Re: regex matching

2001-06-14 Thread Ken
;[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

RE: regex matching

2001-06-14 Thread John Edwards
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

Re: regex matching

2001-06-14 Thread Ken
\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

RE: regex matching

2001-06-14 Thread John Edwards
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]

Re: regex matching

2001-06-14 Thread Paul
--- [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