Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

www.webdp.net, Event 9 IIS log failed to write entry, wwwxxx jeffs, Catastrophic failure Unexpected method call sequence. 0x8000ffff (-2147418113)., ksh lock a file, [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed, sed: -e expression #1, char 1: unterminated address regex, procmail + change subject, w2ksp4.exe download, /proc/kallsyms format

Links

XODOX
Impressum

#1: Regular Expression Help

Posted on 2008-04-16 05:20:32 by chung.ley

------_=_NextPart_001_01C89F70.D96843D3
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi,

=20

I have a program that will take in a string that will resolve to a path
where the output is going to store.

=20

The path can includes "variables" in this format "%<VariableName>%".
The acceptable variableNames that the program will support are fixed to
a list such as "Person", "Class", "Dept". This list may grow in the
future; but for now it is fixed.

=20

So, some of the acceptable strings are:

C:\Windows\%Person%\%Class%

C:\MyHomeDir\%Dept%\%Person%

C:\MyHomeDir\%Dept%_%Person%

and etc...

=20

I like to develop a validate method to return false when the string in
between the % pair don't belong to the acceptable list, and was trying
to do that with an expression.

- Look for the string that is in between the "%" by the closest pair.

- The "%" pair must start at the "odd" occurrence and finish on the
"next even" occurrence... Don't know how to describe this exactly, but
I don't want it to pack this up ("InBetween") from this
(C:\MyHomeDir\%Dept%InBetween%Person) even though it is in between a %
pair.

- Then compare the string within the "%" pair to see if it belongs to
the "acceptable" list or not.

=20

Is using a regular expression the right approach here? or I should just
iterate thru?

=20

Thanks...

=20

--Chung Ley


------_=_NextPart_001_01C89F70.D96843D3--

Report this message

#2: Re: Regular Expression Help

Posted on 2008-04-16 16:24:52 by Rob Dixon

Ley, Chung wrote:
> Hi,
>
>
>
> I have a program that will take in a string that will resolve to a path
> where the output is going to store.
>
>
>
> The path can includes "variables" in this format "%<VariableName>%".
> The acceptable variableNames that the program will support are fixed to
> a list such as "Person", "Class", "Dept". This list may grow in the
> future; but for now it is fixed.
>
>
>
> So, some of the acceptable strings are:
>
> C:\Windows\%Person%\%Class%
>
> C:\MyHomeDir\%Dept%\%Person%
>
> C:\MyHomeDir\%Dept%_%Person%
>
> and etc...
>
>
>
> I like to develop a validate method to return false when the string in
> between the % pair don't belong to the acceptable list, and was trying
> to do that with an expression.
>
> - Look for the string that is in between the "%" by the closest pair.
>
> - The "%" pair must start at the "odd" occurrence and finish on the
> "next even" occurrence... Don't know how to describe this exactly, but
> I don't want it to pack this up ("InBetween") from this
> (C:\MyHomeDir\%Dept%InBetween%Person) even though it is in between a %
> pair.
>
> - Then compare the string within the "%" pair to see if it belongs to
> the "acceptable" list or not.
>
>
>
> Is using a regular expression the right approach here? or I should just
> iterate thru?

If the names are environment variable names, which is implied by your
syntax, then you can substitute the values of those variables as shown
in the program below.

HTH,

Rob


use strict;
use warnings;

my $str = '%windir%\system32';

$str =~ s/%(.*?)%/$ENV{uc $1}/g;

print $str;

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message