[英]Using Regular Expression to extract value
Could someone please help me with this scenario, 有人可以在这种情况下帮助我,
[Some text]
[Some text] Device ID: XYZ123 [Some text]
[Some tex]
I want to extract XYZ123
from the above sample. 我想从上述示例中提取XYZ123
。 Appreciate your help. 感谢您的帮助。
You can use: 您可以使用:
(?<=Device ID: )\b[a-Z0-9]+\b
(get ID via catch group #0) (通过#0捕获组获取ID)
Assuming your regex engine supports lookbehinds, otherwise use: 假设您的正则表达式引擎支持后向,否则请使用:
Device ID: (\b[a-Z0-9]+\b)
(get ID via catch group #1) (通过#1捕获组获取ID)
Note: I herein assume that the [
and ]
are not actually found in your source text, are they? 注意:我在这里假设[
和]
在您的源文本中并未真正找到,对吗?
试试这个 :
\[[^\]]+]\s*Device ID\:\s*(?<DeviceID>[A-Z0-9]+)\s*\[[^\[]+\]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.