Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regualr Expression for: Folder path back one slash
#1
Hi,
I have been trying to figure out the RegEx for taking a folder path back one level

e.g.

folderpath = "C:\Test Level Top\Test Level Top minus 1\Test Level Top Minus 2

to become

upfolderpath = "C:\Test Level Top\Test Level Top minus 1"

I know it's something with substrings and replacerx (e.g. "[sample pattern $2, $1),
but I get confused when it's the LAST of something that I have to remove (i.e. how do you know its the last....)

Any good resources on getting better at RegEx that people know. Maybe a place with exercises or something.

Stuart
#2
Use getpath instead.
#3
I made this into a function using regular expression below.

It assumes the output from a getpath statement from the macro calling this function


Code:
Copy      Help
function str&folderpath str&upalevel

folderpath.rtrim("\");; remove backslash of result from getpath (either in contributing macro or in this function)
;out folderpath

findrx(folderpath "^.+\\" 0 0 upalevel)
;out upalevel

Hope this helps somebody. Any comments or suggestions welcome.

Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)