本文介绍了如何使用正则表达式获得子串的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含0和1个字符串的字符串。我如何获得与给定模式匹配的子串的位置(输入字符串中每个子字符串的开始和结束索引):1 * 100 * 11 *。

(11 * == 111111111 ...,00 * == 0000000 ....)



例如:

regexp pattern = 1 * 100 * 11 *



  string  str =   10100011101101 
index1 = { 0 2 }; // 101
index2 = { 2 8 }; // 1000111
index3 = { 6 11 }; // 111011
index4 = { 10 13 }; // 1101
解决方案




I have a string with 0 and 1 charachers.How do i get the positons of substrings(start and end index of each substring in a input string) that matched with a given pattern: 1*100*11*.
(11*==111111111... ,00*==0000000....)

example:
regexp pattern=1*100*11*

string str="10100011101101"
index1={0,2};//101
index2={2,8};//1000111
index3={6,11};//111011
index4={10,13};//1101
解决方案




这篇关于如何使用正则表达式获得子串的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 09:51