I'm trying to figure out regex to extract last folder name in a given path. I would like regex to by dynamic enough to handle inputs with back slash \ or NO back slash. Also, if there any special characters in the folder name it should replace it with ""
Here are possible inputs vs desired outputs
| Input | Output | 
| C:\PATH\TO\FILE\ | FILE | 
| C:\PATH\TO\FILE | FILE | 
| C:\PATH\ | PATH | 
| C:\PATH | PATH | 
| C:\ | C | 
| C: | C | 
| \\network\something\sblah\what'sup\ | whatsup | 
| \\network\something\sblah\what'sup | whatsup | 
I was able to come up with following regex combined with multiple replace functions
replace(replace(Replace(REGEX_Replace([Field1], '.*\\([^\\]+)\\', '$1'), "'", ""), ":", ""), "\", "")
which gets be close but not exactly what i need, if there is no ending backslash then it adds parent folder name.
Appreciate everyone's help!
Solved! Go to Solution.
Hey @kc20, managed to get this working for your sample data if you'd like to give it a try:
REGEX_Replace(REGEX_Replace([Input], '.*\\([^\\]+)\\?', '$1'), '\W', '')@DataNath that's perfect, thank you!
 
					
				
				
			
		
