ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Nothing happen I dont know why the regular expression seems ok.
Maybe something with m/expr/option. the option are i, g, e but not sure which one is the right one, I try all them.
I'm allowing the next chars:
PHP Code:
From a to z From A to Z "_" [undescore] From 0 to 9 "-" [hypen] or is this [dash]? "." (point) "\" [back slash] and " " [white space]
your logic is wrong. !~ is the NOT of =~
you are finding if NOT ANY legal chars are there.
you need a positive search for illegal chars (think about it)
Code:
if $mystring =~ /[^-.A-Za-z0-9\s]/ ;
Last edited by bigearsbilly; 07-18-2006 at 08:03 AM.
At the end I went to search for the chars that I dont want because my logic seems wrong.
I did the next then:
Code:
if( $mystring =~ m/[!"#\$\%&'()\*\+\,\-\/:<=>\?\@\[\\\]\^\`\{\|\}\~]+/g )# ch
ar ";" is valid after sustitution of "," for ";".
{
print "Error on line: $i a invalid char found aborting the parsing\n";
}
I guess the above is different for what I was doing before, the negation of the regular expression.
All this because it could contained corrupted data which come from the excel file.Thats way I'm looking for any weird char.
I don't thing it could get control char data from the excel file isnt .
Thanks everybody for your comments.
I love this site.
At the end I went to search for the chars that I dont want because my logic seems wrong.
I think it's generally agreed better to have a white list rather than a black list.
i.e. I think the first match is better as you never know what you've missed
with the second method.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.