Dirk,
I'm not a regex pro, but this worked for me: /^\d{4}(-\d{2}){0,2}$/
I tested it with this:
@test = qw( 2004 200412 20041201 2004-12 2004-12-01 );
foreach $test (@test) {
print $test : . ($test =~ /^\d{4}(-\d{2}){0,2}$/ ? TRUE : FALSE)
. \n;
}
Regards,
Mike
-Original
Title: RE: Regex Help
Okay, this is amazingly cloddish, but it does work and may point out where some of your regexes are going wrong. Whenever I have difficulty, I try to simplify it down and then analyze.
@strings = qw/ 2004 200412 20041201 2004-12 2004-12-01/;
for (@strings){
if (/^\d
@listserv.ActiveState.com
cc:
Subject:RE: Regex Help
Dirk,
I'm not a regex pro, but this worked for me: /^\d{4}(-\d{2}){0,2}$/
I tested it with this:
@test = qw( 2004 200412 20041201 2004-12 2004-12-01 );
foreach $test (@test) {
print $test : . ($test =~ /^\d{4}(-\d
: Thursday, January 27, 2005 11:50
To: [EMAIL PROTECTED]
Cc: Dirk Bremer; perl-win32-users@listserv.ActiveState.com;
[EMAIL PROTECTED]
Subject: RE: Regex Help
The reason that 200412 matches in your first regex is that the first
four characters match the pattern (as expected) but there is nothing
Any thoughts?
$lines[0] =~/^(.*?,){36}.*?$/
$lines[0] =~ /^[^,](?:*,[^,]*){36}$/
I like Joe's answer, but if you must use a regex this one works:
print scalar(my @commas = $lines[0] =~ /(,)/g);
- Mark.
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED] wrote:
: I wrote a RegEx to let me know if a line of text has exactly
: 36 commas in it (the comma is the separator) and I came up
: with this. I don't think it is quite right. I could use a
: little pointing in the right direction. Any thoughts?
You could use tr/// to
Title: RegEx help
Jeff Williams wrote, on Tue 12/14/2004
11:23: I wrote a RegEx to let me know if a line of text
has exactly 36 commas init (the comma is the separator) and I came up with
this. I don't think itis quite right. I could use a little pointing in the
right direction.
at 09:23 AM 12/14/2004, Jeff Williams wrote:
I wrote a RegEx to let me know if a line of text has exactly 36 commas in
it (the comma is the separator) and I came up with this. I don't think it
is quite right. I could use a little pointing in the right direction. Any
thoughts?
$lines[0]
There's a fun little idiom using tr/// to count the number of
occurances of a character in a string:
perl -le '$str = a,b,c,d,e; $count = ($str =~ tr/,/,/); print $count'
will output 4, the number of commas in a,b,c,d,e.
--Kester
Jeff Williams wrote, on Tue 12/14/2004 11:23
: I wrote a
$Bill wrote:
... and \1 is deprecated for $1.
I believe that should read [thanks Greg!] ...and \1 is deprecated on the
right
side of s///. On the left side (as in any regexp), \1 and $1 differ. But
as a holdover from sed, \1 means the same as
$1 on the right side of the subst.
\1 isn't the
Title: RE: regex help
Assuming your dates are always in the same format, this would work:
print $1\n while ($_ =~ /(\d{1,2}\:\d{2} [ap]m)/gi);
-Pete
-Original Message-
From: Malcolm Mill [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 02, 2004 4:11 PM
To: [EMAIL
Hi,
Your Find patter is wrong.
Use the following Pattern:
s/([\t]\d{2}[:]\d{2}[\s])/\1/;
Regards,
Gopal.R
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Malcolm Mill
Sent: Wednesday, November 03, 2004 2:41 AM
To: [EMAIL PROTECTED]
Subject: regex help
Ganesh Babu Nallamothu, Integra-India wrote:
Hi,
Your Find patter is wrong.
Use the following Pattern:
s/([\t]\d{2}[:]\d{2}[\s])/\1/;
\t, \s and : do not need to be in a character class and \1 is deprecated for $1.
This should be equivalent:
s/(\t\d{2}:\d{2}\s)/$1/;
You should
Jamie Murray wrote:
Hi Glenn,
I have worked on this further and looked at some of the previous posts.
I have tried this with all different combinations of ip address and this has
worked.
Of course I got the idea from a previous post from Alex and Mark Thomas.
Please understand I could have
Hey Alex,
I jumped a little quick there, the previous post does work but I had a doh
moment and forgot your upper range match could only be 254 at most.
Sorry about that.
if($num =~
/^[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
after each class [] use {num,num} to
f ($ip =~ /^\d[0-254]\.\d[0-254]\.\d[0-254]\.\d[0-254]$/)
incorect way of matching ip address, it will work fore 61.14.95.02,
but will not work for 66.18.99.07. The problem here you just trying to
match 2 digital number instead of 3 digits. For example using [] [aDc]
true for a but not for aa,
On approximately 1/12/2004 8:36 PM, came the following characters from
the keyboard of Jamie Murray:
Hey Alex,
I jumped a little quick there, the previous post does work but I had a doh
moment and forgot your upper range match could only be 254 at most.
Sorry about that.
if($num =~
Jamie Murray wrote:
Hey Alex,
I jumped a little quick there, the previous post does work but I had a doh
moment and forgot your upper range match could only be 254 at most.
Sorry about that.
if($num =~
/^[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]\.[0-2][0-5][0-4]$/)
^^^ ^^^
and am just trying my best.
Thanks!
- Original Message -
From: $Bill Luebkert [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 13, 2004 5:07 AM
Subject: Re: REGEX help!
Jamie Murray wrote:
Hey Alex,
I jumped a little quick there, the previous post does work but I had
Subject: Re: REGEX help!
BiLL,
If you check my second post I made the correction but I'm still correct in
my example and method.
Actually the e-mail from Raul Davletshin pretty much verifys what I had
also stated and he's also correct.
As for explaining [0-2] 0 or 1 or 2 are all possibilities
\.$octet$/o;
print yes if $ip =~ $valid_ip;
- Original Message -
From: Glenn Linderman [EMAIL PROTECTED]
To: Jamie Murray [EMAIL PROTECTED]
Cc: $Bill Luebkert [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Tuesday, January 13, 2004 6:24 PM
Subject: Re: REGEX help!
On approximately 1/13
: Glenn Linderman [EMAIL PROTECTED]
To: Jamie Murray [EMAIL PROTECTED]
Cc: $Bill Luebkert [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Tuesday, January 13, 2004 6:24 PM
Subject: Re: REGEX help!
On approximately 1/13/2004 6:49 AM, came the following characters from
the keyboard of Jamie Murray:
Hi
Thanks for the discussion,clear explanation and advice Glenn.
- Original Message -
From: Glenn Linderman [EMAIL PROTECTED]
To: Jamie Murray [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, January 14, 2004 12:48 AM
Subject: Re: REGEX help!
On approximately 1/13/2004 7:01 PM
];
[EMAIL PROTECTED]
Sent: Tuesday, January 13, 2004 6:24 PM
Subject: Re: REGEX help!
On approximately 1/13/2004 6:49 AM, came the following characters from
the keyboard of Jamie Murray:
Hi guys,
I have seen my error which I have overlooked and don't mind admitting
it.
: ) Course don't hold
just a stab
starts with
any digit(s) = any number of digits or
= 0 or 1 or none(?=can be none but at most 1) followed by any 2 numbers
= 2 followed by number between 0 and 4 followed by any number
= 25 followed by any number between 0 and 5
followed by .
the rest is repeat (I think that
Dax T. Games wrote:
I have a list of characters. I need to get a list of all possble
sequences of these characters for example.
I have a string that consists of '-mevqgn' I need to pattern match any
combination of 'mevqgn' with a preceding - or --.
Right now this is what I am doing
I wanted to use tr but was uanble to accomplish the
task that way. So I used regex like the following:
use strict;
my %MCTWW = qw(m -1 e -1 v -1 q -1 g -1 n -1);my $MyCharsToWorkWith =
\%MCTWW;
$_ = '--mepqgn ';
if ( ! /-{1,2}(\S+)/ ) { printf "Expecting a hyphen
or two floowed by non
Have you tried playing around with character sets? Something like
$target = 'mevqgn';
$length_target = length $target;
if ( $LS_Val =~ /-{1,2}[$target]{$length_target}/ ) {
#do something
}
Whether the above would work for you would depend on whether the code
can ignore positive matches on
Here
is another variation...
#!/usr/bin/perl
check('-mevqgn');check('-memqgn');check('-ngmevq');check('--meqvgn');
sub check{ my $LS_Val = shift;
if ($LS_Val =~ /-{1,2}([mevqgn]{6})/ and
unique_chars($1)) { print "Ding
Ding! $LS_Val is good!\n"; } else
{ print "Flopped:
$LS_Val\n"; }}
On Tue, 2 Sep 2003, Dax T. Games wrote:
I have a list of characters. I need to get a list of all possble sequences of these
characters for example.
I have a string that consists of '-mevqgn' I need to pattern match any combination
of 'mevqgn' with a preceding - or --.
Right now this is
Wow... looks like some good replies to this one. Here's a less
elegant, recursive approach (until I learn map :-)
#!perl -w
# print all 720 permutations using letters: e m v q g n
use strict;
sub mutate {
my ($in) = @_;
if (length($in) == 6) {
print $in\n;
$in = '';
} else {
It looks like you may be doing standard command line option
parsing (or almost standard as the '--' prefix is reserved
for long option names). If this is so, look at GetOpt::Std .
For a subroutine that does what you specified (tested):
sub is_DTG_Option ($)
{
my $opt = shift;
return
Equally dirty, but possibly more flexible:
$_='aSdFgHjk'; # Letters to look
for.
$alpha1=lc(join('',sort(split(//;
$LS_Val=shift;
$LS_Val=~s/^-//g; # Drop preceding dashes
$alpha2=lc(join('',sort(split(//,$LS_Val;
if
($alpha1 eq $alpha2) {print "Pattern found!\n";}
At 01:26 PM 9/2/2003, Dax T. Games wrote:
I have a
list of characters. I need to get a list of all possble sequences
of these characters for example.
I have a string that consists of '-mevqgn' I
need to pattern match any combination of 'mevqgn' with a preceding - or
--.
Right now this is what
$Bill Luebkert wrote:
Dax T. Games wrote:
I have a list of characters. I need to get a list of all possble
sequences of these characters for example.
I have a string that consists of '-mevqgn' I need to pattern match any
combination of 'mevqgn' with a preceding - or --.
Right now this
how
about sorting the letters first:
$var="meqgvn";
$sortedvar=join("", sort(split("",
$var)));
if
($sortedvar eq "egmnqv") { print
"yes!\n";}
--ken
-Original Message-From: Dax T. Games
[mailto:[EMAIL PROTECTED]Sent: Tuesday, September 02, 2003
12:26 PMTo: Perl
I'm trying to match a string which would start with http://,
then a character string where there is one one or more
instances of %, followed by one instance of .com, i.e.
http://www.%55.com
Here is my current pattern:
http://.*%+.*(\.com)
However, if there are two or more
You could cheat a little instead of trying to do it with just a RE, use
an embeded tr/// or s///:
my $text = 'axxxccvvvacassdcxaswrefaejjawerassdcxaswrefaejhhaasera';
$text =~ s#s(.*?)e# my $x = $1; $x =~ tr/a/8/; sprintf 's%se', $x
#eg;
--
Thanks. The main problem I was having was I
Bullock, Howard A. wrote:
You could cheat a little instead of trying to do it with just a RE, use
an embeded tr/// or s///:
my $text = 'axxxccvvvacassdcxaswrefaejjawerassdcxaswrefaejhhaasera';
$text =~ s#s(.*?)e# my $x = $1; $x =~ tr/a/8/; sprintf 's%se', $x
#eg;
Your two little dashes make
Bullock, Howard A. wrote:
I want to alter some characters in a text variable, but only those
between two markers.
$text = 'axxxccvvvacassdcxaswrefaejjawerassdcxaswrefaejhhaasera';
I want to specify the start s and the end e and only change the a's
to 8's between the markers. How do I
* Stephen Patterson ([EMAIL PROTECTED]) wrote:
I have a scalar, $doc, which contains a plain ascii file, and which
I'll be storing on a database (for searching).
(...)
Can anyone help?
There's a module called Whitespace on CPAN, would that work for you?
Additionnally, there's also a
Here is a simplistic approach. May want more edits, but is a starting place.
Placing the data for testing under DATA:
while ( DATA ) {
chomp;
next if ( /^\s*$/ ); # bypass blank lines
if ( /^!--\s(\d+.+)\s\/\s(\d+)\s-- rowv (.+) \/vv (.+) \/v\/row/ ) {
printf
Works but not if you have more or fewer than 2 values in a row.
Do you?
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Wagner-David
Sent: Thursday, January 10, 2002 1:31 PM
To: 'Gordon Brandt'; [EMAIL PROTECTED]
Subject: RE: Regex Help Please
PROTECTED]
Subject: RE: Regex Help Please!
Works but not if you have more or fewer than 2 values in a row.
Do you?
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
Wagner-David
Sent: Thursday, January 10, 2002 1:31 PM
To: 'Gordon Brandt'; [EMAIL
:: -Original Message-
:: From: Gordon Brandt [mailto:[EMAIL PROTECTED]]
:: Sent: Thursday, January 10, 2002 12:17 PM
:: To: [EMAIL PROTECTED]
:: Subject: Regex Help Please!
::
:: [-snip-]
::
:: Input file:
:: |
::
:: (misc header information I want to delete)
::
::
A less elegant (perhaps) solution, but effective, no matter how many rows /
values:
while() {
s/\r//g; # I hate that carriage return
chomp;
next if(!/^.*\!--/); # skip non-matching lines
my @values;
my $ts = $1 if(s/\!--\s*(.*?)\s*--//);
my($ts1,$ts2) =
sday, March 27, 2001 4:05 PM
Subject: Re: Regex Help
Try using this:
use File::Basename; # for picking apart file specs
# filename, directory, extension
#
($filena,$ldir,$ext)
PROTECTED]
Cc: "perl-win32-users" [EMAIL PROTECTED]
Sent: Tuesday, March 27, 2001 4:05 PM
Subject: Re: Regex Help
Try using this:
use File::Basename; # for picking apart file specs
# filename, directory, extension
#
($filena,$ldir,$ext) = fileparse($ARGV[0],'\..*');
I tried this and it seemed to work:
my $InputLine = '(! SUBSTR(DB.USER1,2,5)="9") .AND.
(LEFT(DB.USER1,1)"1") .AND. (ALLTRIM(DB.OUNCEWT)"2")';
my $InputLine1 = '(! SUjSTR(DB.USER1,2,5)="9") .AND.
(LEFT(DB.USER1,1)"1") .AND. (ALLTRIM(DB.OUNCEWT)"2")';
my $Str = '(!
"Bullock, Howard A." wrote:
Is there a way to get the following text to match? If the '\' in '1\V' is
changed, the regex matches. I would like to maintain the RAW text if
possible.
$c = 'JUA_APPS01\VOL1:\APPS';
$d = 'JUA_APPS01\VOL';
if ($c =~ /$d/)
{
print "matched\n";
}
50 matches
Mail list logo