Re: regexp question

2009-09-05 Thread John W. Krahn
Noah Garrett Wallach wrote: Okay I am having troubles finding this. in the perldoc modules. Is there a slicker way to write the following? if ($line =~ /(Blah1)(.*)/) { At this point we know that the pattern matched so $1 will contain the string "Blah1" and $2 will contain a string o

Re: regexp question

2009-09-04 Thread Chas. Owens
On Fri, Sep 4, 2009 at 23:06, Noah Garrett Wallach wrote: > > > Okay I am having troubles finding this. in the perldoc modules. > Is there a slicker way to write the following? > >        if ($line =~ /(Blah1)(.*)/) { >             $blah = $1 if $1; >             $blah2 = $2 if $2; >        } snip

Re: regexp question

2009-09-04 Thread Erez Schatz
2009/9/4 Noah Garrett Wallach : > is there any way to search for the following text?  In some cases the text > that I am search could be > > "one-two-three-" > or sometimes the text could be "one-two-" If you're looking for this specific text then a good answer was already given, but if that's an

Re: regexp question

2009-09-04 Thread Chas. Owens
On Fri, Sep 4, 2009 at 04:08, Noah Garrett Wallach wrote: > > Hi there, > > is there any way to search for the following text?  In some cases the text > that I am search could be > > "one-two-three-" > > or sometimes the text could be > > "one-two-" > > what is a nice easy why to parse the above -

Re: Regexp-Question: What is backtracking?

2009-03-12 Thread Erez Schatz
2009/3/12 Deviloper > Can somebody explain what Backtracking is? > > thanx, > B. > In a nutshell, consider the following regex: /foo((b+)ar)/ a regex engine will check every character in the string that is checked against until it reaches the first "f". When reached, it will mark the place and ch

Re: Regexp question...

2001-12-22 Thread Andrea Holstein
"John W. Krahn" schrieb: > > Andrea Holstein wrote: > > > > A matching always return a list of the captured items. > > On the left side of the assignment is a scalar, > > so list in a scalar context returns its size. > ^ > While this is true that is _n

Re: Regexp question...

2001-12-21 Thread Michael R. Wolf
"John W. Krahn" <[EMAIL PROTECTED]> writes: > $ perl -le'$data = "one two three four five six"; > $test = $data =~ /(\S+)\s+(\S+)\s+(\S+)/; > print "Test 1: $test"; > ($test) = $data =~ /(\S+)\s+(\S+)\s+(\S+)/; > print "Test 2: $test"; > $test = $data =~ /(\S+)\s+(\S+)\s+(\S+)/g; > print "Test

Re: Regexp question...

2001-12-21 Thread John W. Krahn
Andrea Holstein wrote: > > Wim De Hul wrote: > > > > I tried with: > > > > $_ = &snmpget($sysdescr); > > $IOS_version = /Version (.*?)\, /i; > > > > When I do now: print "$1\n"; I get the IOS version > > But when I type print "$IOS_version\n"; It displays just 1... > > Can I get r

Re: Regexp question...

2001-12-21 Thread John W. Krahn
Wim De Hul wrote: > > Hey folks, Hello, > I'm writen a script to manage my router configuration. > To get the IOS version I use regular expressions. > First, I did it with: > > $_ = &getparameter($sysdescr_mib,"System description");# Get > the SysDescr via SNMP > /Version /

Re: Regexp question...

2001-12-21 Thread Andrea Holstein
Wim De Hul wrote: > > Hey folks, > > I'm writen a script to manage my router configuration. > To get the IOS version I use regular expressions. > First, I did it with: > > $_ = &getparameter($sysdescr_mib,"System description");# Get > the SysDescr via SNMP > /Version /; >

Re: regexp question

2001-11-03 Thread Martin Karlsson
Thanks Jeff! Works like a charm! Be well! /Martin * Jeff 'japhy' Pinyan ([EMAIL PROTECTED]) wrote: > On Nov 3, Martin Karlsson said: > > >Could anyone give me a push in the right direction, please? > >How do I write a regexp that matches double instances of letters (in a > >file i read into a va

Re: regexp question

2001-11-03 Thread Jeff 'japhy' Pinyan
On Nov 3, Martin Karlsson said: >Could anyone give me a push in the right direction, please? >How do I write a regexp that matches double instances of letters (in a >file i read into a variable), e.g. aa LL pp etc. ? > >Is there an easy way, or must I use > (aa|bb|cc|... and so on ) ? You

RE: regexp question

2001-10-23 Thread Richard_Cox
On 23 October 2001 12:21 Jerry Preston [mailto:[EMAIL PROTECTED]] wrote: > I want to break down this name, pgrap.C4A2S1R.1.gif, into 4 parts. I > can do it with split: > > ( $a1,$a2,$a3,$a4 ) = split( /\./, $program ); > > How do I do it with s/\b(\.)\b(\.)\b(\.)\b(\.)/? >

Re: regexp question

2001-10-23 Thread register
my $string = 'pgrap.C4A2S1R.1.gif'; my @s = ($string =~ /(?:\.)*(\w+)(?:\.)*/g); the arraytores the elements the //g makes it find more than one match ... post again if you need more explanation ... hth On Tue, Oct 23, 2001 at 06:20:31AM -0500, Jerry Preston shaped the electrons to read: > Hi,

Re: regexp question

2001-10-22 Thread Andrea Holstein
Andrea Holstein wrote: > > ( $a1,$a2,$a3,$a4 ) = $program =~ m/^(.+)\.(.+)\.(.+)\.(.+)$/; > Oh, I see, it's a slow solution. Substitute every (.+) with ([^\.]+) and the pattern matching will be quite quicker. Greetings, Andrea -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional comman

Re: regexp question

2001-10-22 Thread Andrea Holstein
Jerry Preston wrote: > > I want to break down this name, pgrap.C4A2S1R.1.gif, into 4 parts. I > can do it with split: > > ( $a1,$a2,$a3,$a4 ) = split( /\./, $program ); > > How do I do it with s/\b(\.)\b(\.)\b(\.)\b(\.)/? > Don't use substutions when you want to get parts

Re: regexp question

2001-10-21 Thread Andrea Holstein
Birgit Kellner wrote: > > my $header = "Joe DoeThe book I wrote yesterday"; > my $title; > if ($header =~ /(^\S.+)()(\S.+$)/m) { $title = "$1: $3";} > print "$title\n"; > > Is there a shorter, simpler, more efficient way to do this? I still need > $header later on as it is. > I try to go anothe

Re: regexp question

2001-10-19 Thread Jeff 'japhy' Pinyan
On Oct 19, birgit kellner said: >> ($title = $header) =~ s//: /; > >I had thought of that, but believed that it will also perform the >substitution on $header. I just tested it, and that doesn't seem to be the >case. If that's true, there's the solution to my problem. Doing ($x = $y) =~ s/fo

Re: regexp question

2001-10-19 Thread birgit kellner
--On Freitag, 19. Oktober 2001 12:49 -0400 Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: > On Oct 19, birgit kellner said: > >> my $header = "Joe DoeThe book I wrote yesterday"; >> my $title; >> if ($header =~ /(^\S.+)()(\S.+$)/m) { $title = "$1: $3";} >> print "$title\n"; >> >> Is there a shor

Re: regexp question

2001-10-19 Thread Jeff 'japhy' Pinyan
On Oct 19, birgit kellner said: >my $header = "Joe DoeThe book I wrote yesterday"; >my $title; >if ($header =~ /(^\S.+)()(\S.+$)/m) { $title = "$1: $3";} >print "$title\n"; > >Is there a shorter, simpler, more efficient way to do this? I still need >$header later on as it is. You could do: (

Re: regexp question

2001-10-19 Thread Martin
try this: my $title =~ s// /i; if ($header =~ /(^\S.+)()(\S.+$)/m) { $header =~ s///i; } print $header; hope it helps martin birgit kellner wrote: > my $header = "Joe DoeThe book I wrote yesterday"; > my $title; > if ($header =~ /(^\S.+)()(\S.+$)/m) { $title = "$1: $3

Re: Regexp question

2001-06-25 Thread Me
> On Tue, 26 Jun 2001, Tim Wood wrote: > > > Drats - just when I got the regexp worked out too... > > $_=~ m/()/ > > Until you get to the one that is like > > > a bunch of stuff > And of course, when you fix that simple exception, the next slightly more complicated exception comes along.

Re: Regexp question

2001-06-25 Thread Brett W. McCoy
On Tue, 26 Jun 2001, Tim Wood wrote: > Drats - just when I got the regexp worked out too... > $_=~ m/()/ Until you get to the one that is like a bunch of stuff Which is why the parser module is a good idea -- it can handle non-idiomatic cases like this. -- Brett

Re: Regexp question

2001-06-25 Thread Me
> Drats - just when I got the regexp worked out too... > $_=~ m/()/ Kudos for working out the regex that works given your assumptions. If the web pages you will be parsing are known to be constrained to the assumptions you've established, then you're done. But be aware that your regex will fail

Re: Regexp question

2001-06-25 Thread Tim Wood
Drats - just when I got the regexp worked out too... $_=~ m/()/ > > [matching web page links] > > [using regexes] > > Don't use regexes. They aren't the right tools for the task. > > Use one of the cpan modules for parsing web pages. > Some are written specifically for pulling out links. > > htt

Re: Regexp question

2001-06-25 Thread Me
> [matching web page links] > [using regexes] Don't use regexes. They aren't the right tools for the task. Use one of the cpan modules for parsing web pages. Some are written specifically for pulling out links. http://search.cpan.org/

Re: regexp question

2001-06-07 Thread Martin Weinless
Hi, New messages are coming in as I write. Thanks to all. My error was in assuming that because '.' is a metacharacter, the match must start with the initial 's'. However as was pointes out (and in retrospect, it makes perfect sense, the regexp engine is looking for any single character before t

Re: regexp question

2001-06-07 Thread Peter Scott
At 10:10 AM 6/7/01 -0700, Paul wrote: > . matches the r in supernova > n+ matches one or more n's, so it matches the n in supernova > . matches the o in supervova > .? matches one or no characters, so it matches nothing > (successfully, twice) > v* matches any number of v's, includ

Re: regexp question

2001-06-07 Thread Paul
--- Martin Weinless <[EMAIL PROTECTED]> wrote: > take the regexp '.n+..?.?v*.' > > By all that is sacred, if we use the string 'supernova', there should > be no match since there are too many characters before the 'n' Not true. . matches the r in supernova n+ matches one or more n's, so it

Re: regexp question

2001-06-07 Thread Pete Emerson
Martin, Let me take a crack at it, and explain it so that it might help some beginners, too. I wrote this code: $text='supernova'; if ($text=~/.n+..?.?v*./) { print "match.\n"; } which just takes your regular expression and applies it. The if statement is true, I ran it just to make sure.

Re: regexp question

2001-06-07 Thread Michael.Firestone
Yes it should - you haven't anchored the string. If my memory serves me correctly, the engine sees that "rno" of supernova matches the first three tokens in the pattern. The engine then sucks in "va" to match the next two tokens (.?.?) and fails because the v is already used. But, since the

RE: regexp question

2001-06-07 Thread Wagner-David
Since you are not anchoring in way or another(\b or ^ or \W), it meets your criteria of any character then n then Wags ;) -Original Message- From: Martin Weinless [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 07, 2001 08:25 To: [EMAIL PROTECTED] Subject: regexp question Hello,

Re: regexp question

2001-06-07 Thread Peter Scott
At 08:25 AM 6/7/2001 -0700, Martin Weinless wrote: >take the regexp '.n+..?.?v*.' > >By all that is sacred, if we use the string 'supernova', there should be >no match since there are too many characters before the 'n' > >However, any regexp checking code will report a match. Atom by atom: . -

Re: regexp question

2001-06-07 Thread Michael Fowler
On Thu, Jun 07, 2001 at 08:25:05AM -0700, Martin Weinless wrote: > take the regexp '.n+..?.?v*.' > > By all that is sacred, if we use the string 'supernova', there should be > no match since there are too many characters before the 'n' Nope. Consider supern ova ^^ ^

Re: regexp question

2001-06-07 Thread Jeff 'japhy' Pinyan
On Jun 7, Martin Weinless said: >take the regexp '.n+..?.?v*.' > >By all that is sacred, if we use the string 'supernova', there should be >no match since there are too many characters before the 'n' > >However, any regexp checking code will report a match. You're not saying "the string must sta

Re: Regexp Question Again

2001-05-11 Thread Paul
--- "Gross, Stephan" <[EMAIL PROTECTED]> wrote: > I wasn't clear last time. I wrote: > >I want to match the following: > >1) the letters "PT" > >2) a space or nothing > >3) a word that may or may not be in parentheses or even not exist > >and return item #3 (which may be null) > >Example: > >PT

Re: Regexp Question Again

2001-05-11 Thread M.W. Koskamp
- Original Message - From: Gross, Stephan <[EMAIL PROTECTED]> To: 'Beginner Perl' <[EMAIL PROTECTED]> Sent: Friday, May 11, 2001 5:26 PM Subject: Regexp Question Again > I wasn't clear last time. I wrote: > >I want to match the following: > >1) the letters "PT" > >2) a space or nothing

Re: Regexp Question Again

2001-05-11 Thread Jeff Pinyan
On May 11, Gross, Stephan said: >I wasn't clear last time. I wrote: >>I want to match the following: >>1) the letters "PT" >>2) a space or nothing >>3) a word that may or may not be in parentheses or even not exist >>and return item #3 (which may be null) >>Example: >>PT (XYZ) or PT XYZ or PTXYZ

Re: Regexp Question

2001-05-10 Thread Paul
--- Carl Rogers <[EMAIL PROTECTED]> wrote: > Not having Perl up and running, would this work with the > parenthesis?? > $temp = ~ m/PT[\(]*(\w+)[\)]*/; > $value = $1; > I'm sure there is a one-line answer, but I'm too new to know. > > At 05:13 PM 5/10/2001 -0400, Gross, Stephan wrote: > >I w

RE: Regexp Question

2001-05-10 Thread Nic LAWRENCE
How about this? if (/PT\s*\(?(\w+)\)?/) { $value = $1; } PTMatches the PT \s* Matches any number (or no) spaces \(? Matches one or none ('s (\w+) Matches one or many word characters \)? Matches one or none )'s $1Value caught by (\w+) I think. .. .. maybe. > At 05:13 PM 5/10/20

Re: Regexp Question

2001-05-10 Thread Carl Rogers
Not having Perl up and running, would this work with the parenthesis?? $temp = ~ m/PT[\(]*(\w+)[\)]*/; $value = $1; I'm sure there is a one-line answer, but I'm too new to know. At 05:13 PM 5/10/2001 -0400, Gross, Stephan wrote: >I want to match the following: >1) the letters "PT" >2) a space o