CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
regex filter string

 



orange
User

Dec 29, 2014, 4:57 AM

Post #1 of 2 (1002 views)
regex filter string Can't Post

is there a simpler way to do this:

Code
 ($string) = ($string =~ /^\((.*?)\)$/);


thanks.


Zhris
Enthusiast

Dec 29, 2014, 3:34 PM

Post #2 of 2 (953 views)
Re: [orange] regex filter string [In reply to] Can't Post

Hi,

A substitution would be more appropriate. The non greedy ? is probably not necessary either since you are effectively asking for everything between the first and last chars as per the anchors:


Code
$string =~ s/^\((.*)\)$/$1/;


Another alternative could be to use substr if you are certain $string is always a string wrapped in parenthesis:


Code
substr $string, 0, 1, undef; 
substr $string, -1, 1, undef;


Or if you just want to remove any instances of parenthesis:


Code
$string =~ s/[()]//g;


etc...

Regards,

Chris


(This post was edited by Zhris on Dec 29, 2014, 3:40 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives