Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx (?='\\').*$ - Trying to get username from domain\username

Tags:

.net

regex

I have a string like domainA\userNamePaul. I tried this regex (?='\\').*$ but the out put is same as input. I need to get the username without the domain. Any idea what I am doing wrong.

like image 810
Green Code Avatar asked Jan 30 '26 21:01

Green Code


1 Answers

You need to use Positive lookbehind,

(?<=\\).*$

DEMO

Explanation:

(?<=                     look behind to see if there is:
  \\                       '\'
)                        end of look-behind
.*                       any character except \n (0 or more times)
$                        before an optional \n, and the end of the
                         string
like image 93
Avinash Raj Avatar answered Feb 01 '26 15:02

Avinash Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!