Re: Need Regex for phone number
>>>>> "lotug" == lotug writes: lotug> I need regex code to identify 3108222400 phone number. This question was posted (with the same vagueness) to comp.lang.perl.misc. Check out some of the answers there. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Need Regex for phone number
On Fri, Sep 24, 2010 at 12:50 AM, lotug wrote: > I need regex code to identify 3108222400 phone number. > > If all of your phone numbers are ten digit, then: die "$phone_num is not a ten digit number" unless ($phone_num =~ m/^\d{10}$/); Do you need to include any more criteria? Regards, Yogesh
Re: Need Regex for phone number
Ernest, Can you be a bit more detail into what you have and what you want? Thank On 9/23/10, lotug wrote: > I need regex code to identify 3108222400 phone number. > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Sent from my mobile device -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Need Regex for phone number
I need regex code to identify 3108222400 phone number. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Need Regex help !!
In article <[EMAIL PROTECTED]>, Rob Dixon wrote: > Pandey Rajeev-A19514 wrote: >> >> Rob ANderson wrote: >> > >> > Pandey Rajeev-A19514 wrote: >> > > >> > > In short, I have a defined set of pattern that can occur across any >> > > number of lines(scalars) in a buffer (array of scalars) > and I need to print only those lines(Scalars) that contain the full or > partial pattern. For eg. For the buffer @buff (as shown below), I have to > find out the occurance of "FastEthernet" and "down". >> > > >> > > I have pasted a code below : >> > > I join the buffer to make a Scalar and then search for the pattern. >> > > [...] >> > > Now, that the match has been found, I just want to print only those >> > > scalars in @buff which contains the specified pattern. >> > > >> > > The print should be >> > > ifEntry.2.13 = FastEthernet3/9 >> > > lifEntry.20.13 = administratively down [...] Or if you don't need the lines in between the first and second match (as in Rob's example), then maybe a "state-machine"-like marker (I saw an article recently about state machines) will help. John W. Krahn justed posted something similar I think... my $match = ''; while () { if (/.*FastEthernet.*/) { $match = 1; print $_; } if (/.*administratively down.*/ and $match) { print; $match = ''; } } __DATA__ Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet ifEntry.1.13 = 13 ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down This produces: ifEntry.2.13 = FastEthernet3/9 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 lifEntry.20.13 = administratively down But your example only printed one of these, so I'm not sure if that is what you wanted. -K -- Kevin Pfeiffer International University Bremen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need Regex help !!
Pandey Rajeev-A19514 wrote: > > Rob ANderson wrote: > > > > Pandey Rajeev-A19514 wrote: > > > > > > In short, I have a defined set of pattern that can occur across any number of > > > lines(scalars) in a buffer (array of scalars) and I need to print only those lines(Scalars) that contain the full or partial pattern. For eg. For the buffer @buff (as shown below), I have to find out the occurance of "FastEthernet" and "down". > > > > > > I have pasted a code below : > > > I join the buffer to make a Scalar and then search for the pattern. > > > > > > > > > my @buff; > > > $buff[0] = "Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping > > > packet > > > $buff[1] = " ifEntry.1.13 = 13 > > > $buff[2] = " ifEntry.2.13 = FastEthernet3/9 > > > $buff[3] = " ifEntry.3.13 = 6 > > > $buff[4] = " lifEntry.20.13 = administratively down > > > $buff[5] = " ifEntry.2.13 = FastEthernet3/9 > > > $buff[6] = " ifEntry.3.13 = 6 > > > $buff[7] = " lifEntry.20.13 = administratively down > > > > > > $temp = join($",@buff); > > > if($temp =~ /FastEthernet(\n|\d|\w|\.|\/|\s|=)*down/i) { > > > print "MATCH found > > > } > > > *** > > > > > > Now, that the match has been found, I just want to print only those scalars in > > > @buff which contains the specified pattern. > > > > > > The print should be > > > ifEntry.2.13 = FastEthernet3/9 > > > lifEntry.20.13 = administratively down > > > > I'm not sure why you feel the need to join your buffer into a big string. > > From what you describe couldn't you just process each buffer element one by > > one? > > > > foreach my $buffer_entry (@buff) { > > if($buffer_entry =~ /(FastEthernet|down)/i) { > > print $buffer_entry; > > } > > } > > > > Let us know if your trying to do something more complicated that I've not > > understood. > > Yes, I need a tight pattern representation because the buffer I need to parse is > slightly complicated than what I had pasted in the mail. > > /(FastEthernet|down)/i) gives me an option of "FastEthernet" OR "down". > > I want something like "FastEthernet" AND "down". How do we give AND operation ? > > I want my match to be successful only if all the patterns matches. I thought that > there might be an easy way to represent them thru Regex and would not have to do any if-else ckecking. > > Please tell me if you understood my needs or else I will send a bigger mail. Hi Rajeev. It sounds like you have a log file (?) which looks something like Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet ifEntry.1.13 = 13 ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down and you need to find sets of lines which contain both 'FastEthernet' and administratively down. If I'm right, can you explain better how the lines in these sets are related so that we know they belong together, and how we tell where the sets start and end? Just to give us something to talk about, is this any help? Rob use strict; use warnings; while () { print if /FastEthernet/ .. /administratively down/; print "\n" if /administratively down/; } __DATA__ Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet ifEntry.1.13 = 13 ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down OUTPUT ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down ifEntry.2.13 = FastEthernet3/9 ifEntry.3.13 = 6 lifEntry.20.13 = administratively down -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need Regex help !!
Hi Rob, Yes, I need a tight pattern representation because the buffer I need to parse is slightly complicated than what I had pasted in the mail. /(FastEthernet|down)/i) gives me an option of "FastEthernet" OR "down". I want something like "FastEthernet" AND "down". How do we give AND operation ? I want my match to be successful only if all the patterns matches. I thought that there might be an easy way to represent them thru Regex and would not have to do any if-else ckecking. Please tell me if you understood my needs or else I will send a bigger mail. Regards Rajeev -Original Message- From: Rob Anderson [mailto:[EMAIL PROTECTED] Sent: Friday, July 11, 2003 3:13 PM To: [EMAIL PROTECTED] Subject: Re: Need Regex help !! Hi Rajeev, I'm not sure why you feel the need to join your buffer into a big string. >From what you describe couldn't you just process each buffer element one by one? foreach my $buffer_entry (@buff) { if($buffer_entry =~ /(FastEthernet|down)/i) { print $buffer_entry; } } Let us know if your trying to do something more complicated that I've not understood. HTH, Rob "Pandey Rajeev-A19514" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > In short, I have a defined set of pattern that can occur across any number of lines(scalars) in a buffer (array of scalars) and I need to print only those lines(Scalars) that contain the full or partial pattern. For eg. For the buffer @buff (as shown below), I have to find out the occurance of "FastEthernet" and "down". > > I have pasted a code below : > I join the buffer to make a Scalar and then search for the pattern. > > > my @buff; > $buff[0] = "Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet\n"; > $buff[1] = " ifEntry.1.13 = 13\n"; > $buff[2] = " ifEntry.2.13 = FastEthernet3/9\n"; > $buff[3] = " ifEntry.3.13 = 6\n"; > $buff[4] = " lifEntry.20.13 = administratively down\n"; > $buff[5] = " ifEntry.2.13 = FastEthernet3/9\n"; > $buff[6] = " ifEntry.3.13 = 6\n"; > $buff[7] = " lifEntry.20.13 = administratively down\n"; > > $temp = join($",@buff); > if($temp =~ /FastEthernet(\n|\d|\w|\.|\/|\s|=)*down/i) { > print "MATCH found\n"; > } > *** > > Now, that the match has been found, I just want to print only those scalars in @buff which contains the specified pattern. > > The print should be > ifEntry.2.13 = FastEthernet3/9 > lifEntry.20.13 = administratively down > > > Regards > Rajeev > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need Regex help !!
Hi Rajeev, I'm not sure why you feel the need to join your buffer into a big string. >From what you describe couldn't you just process each buffer element one by one? foreach my $buffer_entry (@buff) { if($buffer_entry =~ /(FastEthernet|down)/i) { print $buffer_entry; } } Let us know if your trying to do something more complicated that I've not understood. HTH, Rob "Pandey Rajeev-A19514" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > In short, I have a defined set of pattern that can occur across any number of lines(scalars) in a buffer (array of scalars) and I need to print only those lines(Scalars) that contain the full or partial pattern. For eg. For the buffer @buff (as shown below), I have to find out the occurance of "FastEthernet" and "down". > > I have pasted a code below : > I join the buffer to make a Scalar and then search for the pattern. > > > my @buff; > $buff[0] = "Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet\n"; > $buff[1] = " ifEntry.1.13 = 13\n"; > $buff[2] = " ifEntry.2.13 = FastEthernet3/9\n"; > $buff[3] = " ifEntry.3.13 = 6\n"; > $buff[4] = " lifEntry.20.13 = administratively down\n"; > $buff[5] = " ifEntry.2.13 = FastEthernet3/9\n"; > $buff[6] = " ifEntry.3.13 = 6\n"; > $buff[7] = " lifEntry.20.13 = administratively down\n"; > > $temp = join($",@buff); > if($temp =~ /FastEthernet(\n|\d|\w|\.|\/|\s|=)*down/i) { > print "MATCH found\n"; > } > *** > > Now, that the match has been found, I just want to print only those scalars in @buff which contains the specified pattern. > > The print should be > ifEntry.2.13 = FastEthernet3/9 > lifEntry.20.13 = administratively down > > > Regards > Rajeev > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Need Regex help !!
Hi, In short, I have a defined set of pattern that can occur across any number of lines(scalars) in a buffer (array of scalars) and I need to print only those lines(Scalars) that contain the full or partial pattern. For eg. For the buffer @buff (as shown below), I have to find out the occurance of "FastEthernet" and "down". I have pasted a code below : I join the buffer to make a Scalar and then search for the pattern. my @buff; $buff[0] = "Jul 5 03:22:29.635 cst: SNMP: 10.1.0.1 queue overflow, dropping packet\n"; $buff[1] = " ifEntry.1.13 = 13\n"; $buff[2] = " ifEntry.2.13 = FastEthernet3/9\n"; $buff[3] = " ifEntry.3.13 = 6\n"; $buff[4] = " lifEntry.20.13 = administratively down\n"; $buff[5] = " ifEntry.2.13 = FastEthernet3/9\n"; $buff[6] = " ifEntry.3.13 = 6\n"; $buff[7] = " lifEntry.20.13 = administratively down\n"; $temp = join($",@buff); if($temp =~ /FastEthernet(\n|\d|\w|\.|\/|\s|=)*down/i) { print "MATCH found\n"; } *** Now, that the match has been found, I just want to print only those scalars in @buff which contains the specified pattern. The print should be ifEntry.2.13 = FastEthernet3/9 lifEntry.20.13 = administratively down Regards Rajeev -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need regex
read perldoc -f substr /Jon Jorge Goncalvez wrote: > > Hi, I wanted to have the first 5 elements of a scalar, like for exemple: > my $number= E14011 > > my number2=E1401 > > How can i do this in Perl, thanks? > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need regex to match all UPPERCASE letters?
On Jul 23, KEVIN ZEMBOWER said: >Jeff and John, thanks for your help. I'm invoking my script with a >command line loop: perl -n pop2html.pl 2001-07-16.txt > >The file pop2html.pl, incorporating your suggestion, is: >if (! /[a-z]/) {chomp; print "$_\n"; next;} >if (/^\s*$/) { print "\n"; next;} > >The output of the program is: >WOMEN'S HEALTH > Well, you should re-arrange your order of tests! If the string is made up of ONLY whitespace (like your second test, /^\s*$/, checks), then it ALREADY matches the !/[a-z]/ test. Re-arrange them. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need regex to match all UPPERCASE letters?
Jeff and John, thanks for your help. I'm invoking my script with a command line loop: perl -n pop2html.pl 2001-07-16.txt The file pop2html.pl, incorporating your suggestion, is: if (! /[a-z]/) {chomp; print "$_\n"; next;} if (/^\s*$/) { print "\n"; next;} The tail of the file 2001-07-16.txt is: WOMEN'S HEALTH Endometriosis: A Clinical Review http://www.bmj.com/cgi/content/full/323/7304/93 YOUTH Renewed Hope for the World's Children http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm The output of the program is: WOMEN'S HEALTH YOUTH As you can see, the first line in pop2html.pl is matching everything, and the second line is never executing. I think that this is because the first line matches on any character that is not a lower-case, including spaces and the occasional capital in an abbreviation or first word of a sentence. Thanks, again, for your help. Any other suggestions? -Kevin >>> [EMAIL PROTECTED] 07/23/01 10:00AM >>> On Jul 23, KEVIN ZEMBOWER said: >I need help writing a regular expression that will match lines that have >only upper case letters, and sometimes slashes and spaces, but won't >match lines with mixed case. > >Lines that must be matched are like: >FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY >FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS >PUBLIC HEALTH >HIV/AIDS You should probably just use a regex like: if ($line !~ /[a-z]/) { # it's ok } That regex says "if $line does NOT contain a lower-case letter, let it pass." -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need regex to match all UPPERCASE letters?
On Jul 23, KEVIN ZEMBOWER said: >I need help writing a regular expression that will match lines that have >only upper case letters, and sometimes slashes and spaces, but won't >match lines with mixed case. > >Lines that must be matched are like: >FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY >FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS >PUBLIC HEALTH >HIV/AIDS You should probably just use a regex like: if ($line !~ /[a-z]/) { # it's ok } That regex says "if $line does NOT contain a lower-case letter, let it pass." -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need regex to match all UPPERCASE letters?
$_ !~ /[a-z]/ Easy enough! hth Chris > -Original Message- > From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 23, 2001 8:49 AM > To: < > Subject: Need regex to match all UPPERCASE letters? > > > I need help writing a regular expression that will match > lines that have only upper case letters, and sometimes > slashes and spaces, but won't match lines with mixed case. > > Lines that must be matched are like: > FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY > FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS > PUBLIC HEALTH > HIV/AIDS > > Lines that must NOT be matched include: > Renewed Hope for the World's Children > http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm > AIDS, TB, and Malnutrition Are Triple Threat in Haiti > > Any suggestions are welcomed. Thank you for helping me with > my problem. > > -Kevin Zembower > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need regex to match all UPPERCASE letters?
Try something like this @data = ("FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY", "PUBLIC HEALTH", "Renewed Hope for the World's Children"); foreach $value(@data) { print "$value\n" unless $value =~ /[a-z]+/; } Note. This will match anything it finds, unless there is a lowercase letter in the data. You could make it more complex and search for only caps, spaces and forward slashes, but as long as you are confident of your data source then this should do. HTH John -Original Message- From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]] Sent: 23 July 2001 14:49 To: < Subject: Need regex to match all UPPERCASE letters? I need help writing a regular expression that will match lines that have only upper case letters, and sometimes slashes and spaces, but won't match lines with mixed case. Lines that must be matched are like: FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS PUBLIC HEALTH HIV/AIDS Lines that must NOT be matched include: Renewed Hope for the World's Children http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm AIDS, TB, and Malnutrition Are Triple Threat in Haiti Any suggestions are welcomed. Thank you for helping me with my problem. -Kevin Zembower - E. Kevin Zembower Unix Administrator Johns Hopkins University/Center for Communications Programs 111 Market Place, Suite 310 Baltimore, MD 21202 410-659-6139 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Need regex to match all UPPERCASE letters?
I need help writing a regular expression that will match lines that have only upper case letters, and sometimes slashes and spaces, but won't match lines with mixed case. Lines that must be matched are like: FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS PUBLIC HEALTH HIV/AIDS Lines that must NOT be matched include: Renewed Hope for the World's Children http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm AIDS, TB, and Malnutrition Are Triple Threat in Haiti Any suggestions are welcomed. Thank you for helping me with my problem. -Kevin Zembower - E. Kevin Zembower Unix Administrator Johns Hopkins University/Center for Communications Programs 111 Market Place, Suite 310 Baltimore, MD 21202 410-659-6139 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]