Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Convert String to Regex
System
Is there some easy way in Perl to convert a string to a regex? For instance if I have the string file.txt and I want to generate a regex from that which only matches file.txt and not file!txt, is there some easy way?
Find more posts tagged with
Comments
Migrateduser
See
http://www.perldoc.com/perl5.8.4/pod/perlfaq6.html#How-can-I-quote-a-variable-to-use-in-a-regex-
Brinko Kobrin
Interwoven Staff Engineer
Migrateduser
Awesome, thanks.
megamala
$str = qq(testing$testing);
If print $str the result is only testing not "testing$testing". How can print that one.
TIA
MM Guptha
Migrateduser
If you want the value of $str to be "testing" followed by the value of the variable $testing, then you can use
$str = "testing$testing";
If you want the value of $str to be "testing" followed by the question mark ("?") followed by "testing", then you can use
$str = 'testing$testing';
Brinko Kobrin
Interwoven Staff Engineer
Migrateduser
If you want the value of $str to be "testing" followed by the question mark ("?") followed by "testing", then you can use
$str = 'testing$testing';
Huh? That doesn't make any sense - how does a "$" equal a "?"?
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Migrateduser
It only make sense
before
I've had my morning coffee. Now that I've had a cup, it is obvious that I should have written:
If you want the value of $str to be "testing" followed by the
dollar sign ("$")
followed by "testing", then you can use
$str = 'testing$testing';
Brinko Kobrin
Interwoven Staff Engineer
megamala
Thanks,
if $str = cgi->param('testing'); then how can I print the value with '$'.
TIA
MM Guptha
Migrateduser
You can print the value using:
print $str;
But perhaps you question is, "How can I safely print a string into an HTML response when that string may contain a question mark?" In that case, you could use something like this:
use TeamSite::CGI_lite;
print TeamSite::CGI_lite->escape_html_data($str);
Brinko Kobrin
Interwoven Staff Engineer
megamala
Thanks, I am looking same but I want use in production server where Teamsite not installed. Is there any other perl module do same.
TIA
MM Guptha
Adam Stoller
If you're not interacting with TeamSite - look at CGI.pm (perldoc CGI).
If you're interacting with TeamSite - especially workflow related - then you're generally better off using TeamSite::CGI_lite
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com