Monday, December 28, 2009

Regular expression to match only for any type of symbols.

I'm going to write a simple regex that will validate whether the provided string contains only symbols or not. No alphabet or numbers or spaces are allowed. Giving the expression using Perl, but it will work with any programming language as long as it PCRE.


my $str = "^%^";
if( $str =~ /^[!-\/:-@\[-`\{-~]+$/ ){
print "String contains only symbols.\n";
}


So the actual regex is ^[!-\/:-@\[-`\{-~]+$

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...