Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
regex examples
Ottawa_IWOV
Could someone draw out a quick example of a regex that strips a directory from in front of a file...
(i.e.)
\templatedata\data\docs\file.txt
leaving me with
docs/file.txt
Any help would be great!
Thanks
Lucas Cochrane
lcochrane@dc.com
Find more posts tagged with
Comments
akshathp
If the folder will always be templatedata\data then try something like this
Store the path in a variable lets say $myVar
then
$myVar =~ s/^\\templatedata\\data//;
This would replace the templatedata\data with null. Leaving you with rest of the info in your variable.
Is this what you were looking for?
Akshat Pramod Sharma
Interwoven Inc.
Ottawa_IWOV
So to clarify...
$file = path tp dcr (\templatedata\data\dcr)
$file = $myVar
$file = dcr
Lucas Cochrane
lcochrane@dc.com
akshathp
All you need to do is instead on "myVar" use your variable which has this path stored. As per your example I am assuming it to be "file" variable.
Is that right?
If so, then just use the code I wrote in the previous post and replace "myVar" with "file".
Hope this helps!
Akshat Pramod Sharma
Interwoven Inc.
Ottawa_IWOV
Iam still confused at to how to use it in the code. I either get everything or nothing
Lucas Cochrane
lcochrane@dc.com
dennispluken
Assuming:
my $path = "iwmnt/main/default/branchname/WORKAREA/yourname/dir_1/dir_2/file_1.html";
This regex will return the directory and the file name:
my ($directory,$filename) = $path =~ m!(.*/)([^/]*)$!;
For NT replace all instances of / with \\.