Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell - regex to get string between two strings

I'm not very experienced in Regex. Can you tell me how to get a string value from between two strings?

The subject will always be in this format : //subject/some_other_stuff

I need to get the string found between // and /.

For example:

Full String = //Manhattan/Project

Output = Manhattan

Any help will be very much appreciated.

like image 260
Yad Avatar asked Jan 10 '23 15:01

Yad


1 Answers

You can use a negated character class and reference capturing group #1 for your match result.

//([^/]+)/

Explanation:

//         # '//'
(          # group and capture to \1:
  [^/]+    #   any character except: '/' (1 or more times)
)          # end of \1
/          # '/'
like image 167
hwnd Avatar answered Jan 12 '23 03:01

hwnd