jhnferraris
jhnferraris

Reputation: 1401

Regex getting the first backslash

I got this string:

use \blahblah\file

I need to get use \ using a regex. For now I got, \suse but I can't figure out how to get the first backslash. Any thoughts?

Thanks!

Upvotes: 0

Views: 177

Answers (3)

vks
vks

Reputation: 67998

^.*?\\

Try this. See demo.

http://regex101.com/r/hQ1rP0/35

Upvotes: 2

aelor
aelor

Reputation: 11116

you need to get use \, then use use \. remember we need to escape characters with special meaning in regular expressions

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174874

You could try the below regex to get the chars upto the first \(including \ )

^[^\\]*\\

DEMO

Upvotes: 2

Related Questions