expression - Regex to get words within a Backslash -


following string: f:\shared\common\1a\gruwr050.pdf

how strings preceding 3rd backslash using regex?

for example: f:\shared\common

use ^(?:[^\\]*\\){2}[^\\]* pattern.

here's python example:

>>> re.findall(r'^(?:[^\\]*\\){2}[^\\]*', r'f:\shared\common\1a\gruwr050.pdf') ['f:\\shared\\common'] 

javascript example:

'f:\\shared\\common\\1a\\gruwr050.pdf'.match(/^(?:[^\\]*\\){2}[^\\]*/) // => ["f:\shared\common"] 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -