简体   繁体   English

用于提取节号和描述的正则表达式

[英]Regular expression to extract Section Number and Description

Am having following data and I would like to extract section number and description in two separate strings.我有以下数据,我想在两个单独的字符串中提取节号和描述。

I am using the following expression - (\d+(?>\.\d+)*)(.\D*) .我正在使用以下表达式 - (\d+(?>\.\d+)*)(.\D*) However, in the description I am seeing '. '但是,在我看到的描述中'. ' '. ' value and I want the dot to be in the section identified. '. '值,我希望点在标识的部分中。

Can someone help me with this?有人可以帮我弄这个吗?

Here are my sample strings -这是我的示例字符串 -

1.1.1. ABC
1.1.2. DEF
1.1.2.3. XYZ

Expecting -期待——

No|Description
1.1.1.|ABC
1.1.2.|DEF
1.1.2.3.|XYZ

Based on your shown samples, could you please try following.根据您显示的示例,您能否尝试以下操作。 Online demo of this is: Online demo of regex在线演示是:正则表达式在线演示

(?P<serial>(?:\d+\.)+)\s*(?P<description>\S+)

Explanation: Adding detailed explanation for above.说明:为上述添加详细说明。

(?P<serial>           ##Starting a named capturing group named serial here.
(?:\d+\.)+)           ##Starting a non capturing group which is looking for continuous occurrence of digits followed with dot with 1 or more occurrences of this combinations.
\s*                   ##Looking for 1 or more occurrences of spaces here.
(?P<description>\S+)  ##Starting a named capturing group named description here which has all values except spaces occurrences.

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

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