正则表达式在冒号后匹配字符串 [英] Regex to match a string after colon

查看:876
本文介绍了正则表达式在冒号后匹配字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入字符串如下:OU = TEST:This001。我们需要额外的 This001。最好的C#。

Input string is something like this: OU=TEST:This001. We need extra "This001". Best in C#.

推荐答案

怎么样:

/OU=.*?:(.*)/

这是它可以正常工作:

OU=  // Must contain OU=
.    // Any character
*    // Repeated but not mandatory
?    // Ungreedy (lazy) (Don't try to match everything)
:    // Match the colon
(    // Start to capture a group
  .    // Any character
  *    // Repeated but not mandatory
)    // End of the group

对于 / 是分隔符,用于知道正则表达式在哪里开始,在哪里结束(以及添加选项)。

For the / they're delimiters to know where the regex start and where it ends (and for adding options).

捕获的组将包含 This001

但是使用简单的 Substring()。

But it would be faster with a simple Substring().

yourString.Substring(yourString.IndexOf(":")+1);






资源:

  • regular-expressions.info

这篇关于正则表达式在冒号后匹配字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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