Re: Regex Needed
Unpack is even faster, for fixed-format strings. dZ. On Mar 24, 2006, at 22:19, Chris Wagner wrote: At 10:38 AM 3/24/2006 -0700, Paul Rousseau wrote: I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Do u have to examine those as fixed strings or as variable strings? Meaning do u know ahead of time which format ur looking at. If u don't know the format ahead of time then u should use the regex. But if u do know the format ahead of time (like it never changes for one application) then u shouldn't use a regex. Using substr will be faster. xxxN yyy sssNNN $s = substr $string, 13, 3; xxxN yyyNyyy sss $s = substr $string, 13, 3; xxxN yyyNyyy ssN $s = substr $string, 13, 6; #don't know what format $string will be $s = $string =~ m/\S+ \S+ ([a-z])+/i; -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regex Needed
Paul Rousseau wrote, on Friday, March 24, 2006 12:38 PM :I am looking for help on a regex that examines strings such as : : xxxN yyy sssNNN : xxxN yyyNyyy sss : xxxN yyyNyyy ssN : : and returns only the sss part? N is always a numeral, and s : is always alphabetic. Does /.*(\d+)/ do what you want? Or is there more to the string after what you've shown? Good luck, Joe ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regex Needed
[EMAIL PROTECTED] wrote: Hello, I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Here is what I have so far as an example. I believe there is an eloquent way to do this in a single regex. my ( $string, $prefix ); $string = MBH1 WELL PIT050; ($prefix) = $string =~ # I want $prefix to equal PIT if it is really of that format then /\s(\D+)\d+$/ is one shot which looks for a space followed by NON Numeric and then alpha and then end of line or data. Wags ;) Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regex Needed
$string = MBH1 WELL PIT050; $string =~ s/.* (.*?)\d+/\1/; # Questionmark makes it non-greedy ($prefix) = $string; # Didn't figure out how to do ($prefix) = $string =~ print $prefix; ; ** Hello, I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Here is what I have so far as an example. I believe there is an eloquent way to do this in a single regex. my ( $string, $prefix ); $string = MBH1 WELL PIT050; ($prefix) = $string =~ # I want $prefix to equal PIT Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regex Needed
Paul, Give this a shot: /^\w+\s+\w+\s+([A-Za-z]+)\d+/ A regex should be as explicit and exclusive as possible, so I would remove the lowercase (a-z) portion of the character class if you know for sure that the letters you want will always be uppercase. -Brian _ Brian H. Oak CISSP CISA Acorn Networks Security http://acornnetsec.com/ Hello, I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Here is what I have so far as an example. I believe there is an eloquent way to do this in a single regex. my ( $string, $prefix ); $string = MBH1 WELL PIT050; ($prefix) = $string =~ # I want $prefix to equal PIT Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regex Needed
Try this: $string =~ /^.{3}\d\s[^\s]+\s([a-zA-Z]+)\d+$/; $prefix = $1; That should match: - any three characters at the beginning of the string: ^.{3} - followed by a number: \d - followed by whitespace: \s - followed by any one or more characters until the next whitespace [^\s]+ - followed by whitespace: \s - grab all the following characters that are letters: ([a-zA-Z]+) - followed by 1 or more numbers until the end of the string: \d+$. Is that an accurate description? -dZ. - Original Message - From: Paul Rousseau Sent: 3/24/2006 1:38:07 PM To: Perl-Win32-Users@listserv.ActiveState.com Subject: Regex Needed Hello, I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Here is what I have so far as an example. I believe there is an eloquent way to do this in a single regex. my ( $string, $prefix ); $string = MBH1 WELL PIT050; ($prefix) = $string =~ # I want $prefix to equal PIT Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regex Needed
Something like this : /(\w\s){2}([a-zA-Z]+)\d*/ David Joe Discenza wrote: Paul Rousseau wrote, on Friday, March 24, 2006 12:38 PM :I am looking for help on a regex that examines strings such as : : xxxN yyy sssNNN : xxxN yyyNyyy sss : xxxN yyyNyyy ssN : : and returns only the sss part? N is always a numeral, and s : is always alphabetic. Does /.*(\d+)/ do what you want? Or is there more to the string after what you've shown? Good luck, Joe ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regex Needed
At 10:38 AM 3/24/2006 -0700, Paul Rousseau wrote: I am looking for help on a regex that examines strings such as xxxN yyy sssNNN xxxN yyyNyyy sss xxxN yyyNyyy ssN and returns only the sss part? N is always a numeral, and s is always alphabetic. Do u have to examine those as fixed strings or as variable strings? Meaning do u know ahead of time which format ur looking at. If u don't know the format ahead of time then u should use the regex. But if u do know the format ahead of time (like it never changes for one application) then u shouldn't use a regex. Using substr will be faster. xxxN yyy sssNNN $s = substr $string, 13, 3; xxxN yyyNyyy sss $s = substr $string, 13, 3; xxxN yyyNyyy ssN $s = substr $string, 13, 6; #don't know what format $string will be $s = $string =~ m/\S+ \S+ ([a-z])+/i; -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs