in reply to Regex output incorrect

Running your sample code I get:

folderpath: /aboutiso/corp_gov/bod/agendas/2010/

Your regex doesn't match the $folder_path string at all because the regex requires a \w character at the end but the $folder_path string ends with a /. No match so no replacement so the string remains unchanged.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Regex output incorrect
by begood321 (Novice) on Dec 14, 2010 at 02:17 UTC

    Hi GrandFather,

    I had a typo which I corrected actually no slash is at the end of folder_path. Correct code is below, still producing incorrect output

    my $folder_path = "/aboutiso/corp_gov/bod/agendas/2010"; my $try = "index.html"; my $test = "$folder_path/$try"; $folder_path =~ s#/\w+/[^/]*.\w+$##; print "folderpath: $folder_path\n";