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)
RegEx question
Hazzie
Can someone help me with a RegEx puzzler.
I have a string (directory path) which could be in any of the following formats
2004\contact_us\contact_us_title
contact_us\contact_us_title
contact_us_title
The amount of directorys is not fixed.
I want to find the ending string
So in
2004\contact_us\contact_us_title i want contact_us_title
contact_us\contact_us_title i want contact_us_title
contact_us_title i want contact_us_title
I have tried all sorts but for example
$DirPath =~ /\\(.*)$/;
which gives me 2004\contact_us\cu_find_branch_results_title
$DirPath =~ /\\?(.*)$/;
which gives me 2004\contact_us\contact_us_title
$DirPath =~ /\\(.*?)$/;
which gives me contact_us\contact_us_title
$DirPath =~ /\\(.*)?$/;
which gives me contact_us\contact_us_title
can anyone give me some pointers as where to go next.
Hazzie
TS 5.5.2 on NT.
Find more posts tagged with
Comments
Adam Stoller
Normally I recommend translating all '\' to '/' as it makes writing regex's much simpler because yo don't have to deal with escaping escape characters.
In this case - it would be something like:
$DirPath =~ tr|\\|/|;
(my $lastElem = $DirPath) =~ s|^.*/||;
However, notwithstanding the escape problem - you could probably do
(my $lastElem = $DirPath) =~ s|^.*\\||;
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Hazzie
Thanks for that fish.
Funny how i just got it into my head that i had to match the text and didnt try to think round the problem and use other methods.
A few mins after posting it dawned on me to try deleting the unwanted text rather than trying to match the unwated text when your email came through.
Cheers for the help.
Hazzie
TS 5.5.2 on NT.