简体   繁体   English

使用Perl5Matcher的正则表达式模式

[英]Regex Pattern using Perl5Matcher

I am trying to write the pattern matcher for the below string 我正在尝试为以下字符串编写模式匹配器

show int sh 1/1/06
SHDSL 1/1/6 
Description                      3599979
Constellation (bits/baud)        30

I need to get the value of 'show int sh' and 'SHDSL' and 'Description' and so on... 我需要获取'show int sh'和'SHDSL'和'Description'等的值...

It should shrink the white spaces and get the value of respective strings. 它应该缩小空格并获得相应字符串的值。

Can any one guide me to write the regex pattern for the same.? 任何人都可以指导我编写相同的正则表达式模式吗?

You can use this regex in multiline mode 您可以在多行模式下使用此正则表达式

^show int sh\\s*(.*)$

^show int sh\\s* checks for show int sh at the start ^ of the line before the required data ^show int sh\\s*检查所需数据之前的行开始^处的show int sh

\\s* matches 0 or more space till the first non space character \\s*匹配0或更多空格,直到第一个非空格字符

(.*)$ captures the required value till end of the line $ in group 1 (.*)$捕获所需的值,直到组1中的 $行结束

So here are all the regex's 所以这是所有正则表达式的

Use multiline mode 使用多行模式

^show int sh\\s*(.*)$

^SHDSL\\s*(.*)$

^Description\\s*(.*)$

^Constellation\\s*(.*)$

OR a single regex 单个正则表达式

^((show int sh|SHDSL|Description|Constellation)\\s*).*$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM