Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find text between second and third slashes

Tags:

I would like to capture the text that occurs after the second slash and before the third slash in a string. Example:

/ipaddress/databasename/

I need to capture only the database name. The database name might have letters, numbers, and underscores. Thanks.

like image 237
user2434549 Avatar asked May 30 '13 00:05

user2434549


1 Answers

How you access it depends on your language, but you'll basically just want a capture group for whatever falls between your second and third "/". Assuming your string is always in the same form as your example, this will be:

/.*/(.*)/ 

If multiple slashes can exist, but a slash can never exist in the database name, you'd want:

/.*/(.*?)/ 
like image 153
Eli Avatar answered Oct 22 '22 00:10

Eli