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
Post a Comment