Regex Help.

2006-06-24 Thread Sara
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.



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.

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 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]
>  
>
>
>
>
> -- 
> 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]