GrSrv
GrSrv

Reputation: 559

Sanitizing a string in Perl

I'm reading an excel(.xlsx) file (using module Spreadsheet::XLSX) and getting values like : Iron/ Steel. 

Problem: The characters  and are not (visible) in the excel file. The rightmost character looks like a white space but isn't as I tried the regex /\s+$/ which didn't work.

Please help how I can clean this string. I want only those characters in my string which are on general English keyboards, i.e., A-Z, 0-9, ~!@#$%^&*()_+=- ` ,./';[]\|}{:"?>< etc.

Upvotes: 0

Views: 1809

Answers (2)

Jan Sielemann
Jan Sielemann

Reputation: 11

When it's always the same position, I think a substr($string, 0, -3) can help!

Upvotes: 1

mpapec
mpapec

Reputation: 50667

You can remove all non ascii chars,

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

Upvotes: 4

Related Questions