PowerShell - 正则表达式获取两个字符串之间的字符串 [英] PowerShell - regex to get string between two strings

查看:84
本文介绍了PowerShell - 正则表达式获取两个字符串之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对正则表达式不是很有经验.你能告诉我如何从两个字符串之间获取一个字符串值吗?

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

主题将始终采用以下格式://subject/some_other_stuff

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

我需要获取在 /// 之间找到的字符串.

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

例如:

Full String = //Manhattan/Project

Full String = //Manhattan/Project

输出 = 曼哈顿

非常感谢任何帮助.

推荐答案

您可以使用否定字符类和引用捕获组 #1 作为匹配结果.

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

//([^/]+)/

说明:

//         # '//'
(          # group and capture to \1:
  [^/]+    #   any character except: '/' (1 or more times)
)          # end of \1
/          # '/'

这篇关于PowerShell - 正则表达式获取两个字符串之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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