RE: Regex Help.

2006-06-25 Thread Charles K. Clarkson
Lou Hernsen wrote:

: and if I want to include certain german umlutted vowels like
: ö and ä i would add them like this?
: $string =~ tr/-_a-zA-Z0-9öä//cd;
: 

What happened when you tested it?


: then what does this do? (from parsing SDTIN)
:
: $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Well, the left hand side of the s operator is a regular
expression. This expression is looking for a percent sign (%)
followed by an hex number, followed by another hex number. If a
match is found, then the hex numbers are placed in $1.

The right hand side of the s operator is a replacement string.
It is normally interpolated (or treated as a double quoted
string), except when the e modifier is included. In this case the
e modifier executes the replacement or right hand side of the s
operator.

The result of the execution of the right hand side will 
replace the percent sign followed by a hex number followed by
another hex number in $name. The g modifier will do this
repeatedly.

This is all explained in more detail in the file 'perlop'
under the Quote and Quote-like Operators section. You can read
about the pack() function in 'perlfunc'.


: $name =~ tr/\0//d; ### replaces zero values to empty

In this case \0 is equivalent to ASCII 0 or chr(0). The d
modifier deletes matched, but unreplaced characters in $name.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regex Help.

2006-06-24 Thread Lou Hernsen
and if I want to include certain german umlutted vowels like ö and ä i would
add them like this?
$string =~ tr/-_a-zA-Z0-9öä//cd;

then what does this do? (from parsing SDTIN)

$name =~ tr/+/ /; ### I know this replaces +'s for spaces
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; ### no clue
at all
$name =~ tr/\0//d; ### replaces zero values to empty

I know you want me to use modules, but I am trying to learn the syntax,
please help with a real answer. I want to be able to filter out undesired
charecters so I think I should add

$name =~ tr/-_a-zA-Z0-9öä//cd;

to the code so it look like this.

 @pairs = split ( /&/, $Input );
   foreach $pair(@pairs)
   {
  ( $name, $value ) = split ( /=/, $pair );
  $name =~ tr/+/ /; #changes plus sign to space
  $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $name =~ tr/\0//d;
  $name =~ tr/-_a-zA-Z0-9öä//cd;
  $value =~ tr/+/ /;#changes plus sign to space
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ tr/\0//d;
  $value =~ tr/-_a-zA-Z0-9öä//cd;
  $Input{$name} = $value;
 }

in a previous question I asked at what point an input with a lynx command
like sys or exec is acted on by the program.
Never got an answer. can I filter out these commands using tr/ or s/ or that
taken care of with -T in hte shebang line?

thanks
Lou


- Original Message - 
From: "Charles K. Clarkson" <[EMAIL PROTECTED]>
To: 
Sent: Saturday, June 24, 2006 4:15 PM
Subject: RE: Regex Help.


> Sara wrote:
>
> : Need help to remove EVERY thing (non-alphabets, symbols,
> : ASCII codes etc) from a string except for a-zAZ, 0-9,
> : dash and underscore.
> :
> : $string =~ s/??
>
>
> Read perlop: Quote and Quote-like Operators
>
>
> $string =~ tr/-_a-zA-Z0-9//cd;
>
>
> HTH,
>
> Charles K. Clarkson
> -- 
> Mobile Homes Specialist
> Free Market Advocate
> Web Programmer
>
> 254 968-8328
>
> Don't tread on my bandwidth. Trim your posts.
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.394 / Virus Database: 268.9.2/372 - Release Date: 6/21/06
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Regex Help.

2006-06-24 Thread Charles K. Clarkson
Sara wrote:

: Need help to remove EVERY thing (non-alphabets, symbols,
: ASCII codes etc) from a string except for a-zAZ, 0-9,
: dash and underscore.
: 
: $string =~ s/??


Read perlop: Quote and Quote-like Operators


$string =~ tr/-_a-zA-Z0-9//cd;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regex Help.

2006-06-24 Thread Mr. Shawn H. Corey
On Sun, 2006-25-06 at 00:14 +0500, Sara wrote:
> Need help to remove EVERY thing (non-alphabets, symbols, ASCII codes etc) 
> from a string except for a-zAZ, 0-9, dash and underscore.
> 
> $string =~ s/??
> 
> Thanks,
> Sara.
> 

By dash, I assume you mean ASCII character 0x2D.

English version:

  $string =~ s/[^-0-9A-Za-z_]//g;

Non-English version:

  use locale;
  use POSIX;

  $string =~ s/[^-[:alnum:]]//g;

See:
  perldoc perlretut
  perldoc perlre
  perldoc locale
  perldoc POSIX


-- 
__END__

Just my 0.0002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regex Help!

2004-03-21 Thread Wiggins d'Anconia
Sara wrote:
I am looking for a regex which would extract the intials from a
string i.e.
str = "Doe, John L.L.M";

$str =~ /(^(\w)).*?((\s)(\w)).*?((\s)(\w))/;

$initial = $1.$2.$3;

print "$initial";

The above code is not serving my purpose.

String constants: There would be always 3 words (obvioulsy with 2
spaces in between) in the string however string may contain periods
(.) and (,) in it. I am looking to extract.
Negation is probably easiest in the case that you know a word does NOT 
contain a space...

1. First Character of the string.
2. Next two Characters after space in the String.
#!/usr/local/bin/perl
use strict;
use warnings;
my $str = "Doe, John L.L.M";

if ($str =~ /^(\S)\S*\s(\S)\S*\s(\S)\S*/) {
print "$2.$3.$1\n";
}
else {
warn "Pattern failed";
}
Doe, John L.L.M should be "DJL"
Simth, G. M.D. should be "SGM"
Interesting order for initials, you will have to adjust mine back...

Any help, please?
HTH,

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: regex help

2001-08-22 Thread Jeffl

Well only you can be the judge if you are doing it right. But what that
expression tells me is:

$string matches, starting with either ( a word, a dot, a hyphen, a at sign,
a colon, a plus sign, a question mark, a bang) one or more times, and
ending in one of the afore mentioned.

So if that is what you want to check for then my guess is that you are
correct, however I would also check for ';' and '&&' and '&' but then you
have all you're control characters to look out for, and you also have to
watch out for the back tick.

My suggestion would be to use #!/usr/bin/perl -w -T
Then scan to see if it contains the characters you do want, not the ones
you don't. I would guess that the characters you will allow is much
simplier than the ones you won't.

my( $string ) =~ $q->param( "string" ) =~ /^([\w.])$/;

unless ($string) {
   print "ERROR, invalid characters used.! Character =
 $string";
  exit;
}

Just my two cents.

Jeff

On 2001.08.23 00:48 Sergio Gonzalez wrote:
> Can anyone tell me if i'm doing this right?
> #check for dangerous characters
> 
> unless ($string =~ /^[\w .-\@:+?!]+$/) {
> print "ERROR, invalid characters used.! Character =
> $string";
>exit;
>   }
> 
> thank you,
> 
> Sergio Gonzalez
> 
> 
> -- 
> 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]