首页 > 解决方案 > 使用特定模式提取子字符串

问题描述

我需要提取一些我从另一个进程接收到的数据。接收到的内容在长度和格式上变化很大,但我需要一条信息始终采用相同的格式。

示例 1:

This is the first example (with a lot of content that I don't need) but the important piece of info is this: (test1 / jibberish)

示例 2:

This is another example (test2 / something I'm not interested in) 

我感兴趣的唯一信息是一个始终具有相同模式的字符串

(信息/一些代码)

这只是我感兴趣的“信息”位。那么有什么东西(比如正则表达式?)我可以用来提取一个临时字符串(甚至可能没有括号),然后我可以在使用 / 时执行一个子字符串?

所以输出变成

info

谢谢

标签: c#regexsubstring

解决方案


在记事本++中我会查找:-\((.+?)\/.+ 替换:-\1


推荐阅读