正则表达式在第二个和第三个斜杠之间查找文本 [英] Regex to find text between second and third slashes

查看:42
本文介绍了正则表达式在第二个和第三个斜杠之间查找文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获字符串中出现在第二个斜杠之后和第三个斜杠之前的文本.示例:

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

/ipaddress/databasename/

/ipaddress/databasename/

我只需要捕获数据库名称.数据库名称可能包含字母、数字和下划线.谢谢.

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

推荐答案

您如何访问它取决于您的语言,但您基本上只需要一个捕获组来处理您的第二个和第三个/"之间的任何内容.假设您的字符串始终与您的示例格式相同,这将是:

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:

/.*/(.*?)/

这篇关于正则表达式在第二个和第三个斜杠之间查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆