Hi,I need to write a regex to check '.html', '.asp' etcEg : Say my iw_file is \test1\test2\abcd.html I want to write a regex to extract '.html' from the iw_file.A quick reply is highly appreciated.Thanks and Regards,Jay
Hi,Is anything wrong the following code :foreach $gen_file (@iw_files) { my $file = $gen_file; if ($file =~ m/templatedata\\(.[^\\]*)\\(.[^\\]*)\\data\\(.[^\\]*)/) { my $generate_file = $file; print LOG "File generated is: $generate_file\n\n\n";} else { my $generate_file = $file; print LOG "File1 generated is: $generate_file\n\n\n";} print LOG "For generated is: $generate_file\n\n\n"; } print LOG "Out generated is: $generate_file\n\n\n";I am getting nothing printed for 'For generated' and 'Out generated', though the 'File' and File1' are getting values and gets printed.Can you help me?Regards,Jay
Is anything wrong the following code :
If I may continue on Jeff's train of thought,6. You're posting on DevNet something that should take you less than a minute and given due diligence and the minimal time investment on your part to look over your code, you would/should see the occasional error, thus reducing the perception that the only reason you're posting something like this on DevNet is that you just want someone to do your work for you.
Cool off? This is a forum -- what's the big deal? Further, there is etiquette pertaining to posts -- part of which is to give an attempt at something before posting a request for help. Not all, but many who lurk here get annoyed when someone posts a question that's either painfully obvious or reflects that s/he has not done their part in trying to figure out a solution.Jay wants to start learning Perl. That's great but this is not the place to do that. There are countless resources on the internet to do that -- but again, this is not one of them.
my $fileName = ("/default/main/b.asp"); # find if it has the file extension. if(($fileName =~ /\.asp/)||($fileName =~ /\.html/)) { print "found it"; } else { print "not found" } # remove file extension $fileName =~ s/.asp//; print "\n".$fileName;
I'm a beginner at perl and regex, but is this what you are looking for? I gave two examples, in case you're just looking to find it or if you are looking to strip off the file extension. my $fileName = ("/default/main/b.asp"); # find if it has the file extension. if(($fileName =~ /\.asp/)||($fileName =~ /\.html/)) { print "found it"; } else { print "not found" } # remove file extension $fileName =~ s/.asp//; print "\n".$fileName;
my $fileName = ("/default/main/casper.asp"); # find if it has the file extension. if($fileName =~ /[\.asp,\.html]$/) { print "found it"; } else { print "not found" } # remove file extension $fileName =~ s/\.asp$//; print "\n".$fileName;
use strict; my $fileName = ("/default/main/asper.html"); # find if it has the file extension. if($fileName =~ /\.asp$|\.html$/) { print "found it"; } else { print "not found" } # remove file extension $fileName =~ s/\.asp$|\.html$//; print "\n".$fileName;
[left] use strict; my $fileName = ("/default/main/asper.html"); # find if it has the file extension. if($fileName =~ /\.(asp|html?)$/i) { print "found it"; } else { print "not found"; } # remove file extension $fileName =~ s/\.(asp|html?)$//i; print "\n".$fileName;[/left]
I realize this might not be real code, etc., but if you were to remove either of those file extensions, wouldn't you want to do that in your IF statement? Otherwise, if you want to remove ANY file extension, your regex would need to be different.