C++ C++;索引处的正则表达式

C++ C++;索引处的正则表达式,c++,regex,C++,Regex,由于字符串序列为0和1,我需要创建一个正则表达式,该正则表达式在多个位置匹配多个子字符串 Example: string sequence: "001100110111100010100101000011111010" substring1: "1100" position1: 2 substring2: "10" position2: 3 substring3: "10001" position3: 12 如果所有子字符串在所有给定位置都匹配,则应返回true或false Examp

由于字符串序列为0和1,我需要创建一个正则表达式,该正则表达式在多个位置匹配多个子字符串

Example:
string sequence: "001100110111100010100101000011111010"
substring1: "1100"  position1: 2
substring2: "10"    position2: 3
substring3: "10001" position3: 12
如果所有子字符串在所有给定位置都匹配,则应返回true或false

Example:
string sequence: "001100110111100010100101000011111010"
substring1: "1100"  position1: 2
substring2: "10"    position2: 3
substring3: "10001" position3: 12
< C++ >

中可以编写这样的正则表达式吗? 谢谢你的帮助

const char * sequence = "001100110111100010100101000011111010";       
boost::regex e("??1100??????10001");
bool all_present = boost::regex_match ( sequence, e );
第二种方法:

  const char * sequence = "001100110111100010100101000011111010";       
  boost::regex exp1("1100");
  boost::regex exp2("10");
  boost::regex exp3("10001");

  bool all_present = boost::regex_match ( sequence, sequence + 2, exp1) &&  
                     boost::regex_match ( sequence, sequence + 3, exp2) &&
                     boost::regex_match ( sequence, sequence + 12, exp3);

为什么不为每个可能的子字符串使用substr()函数呢?为了提高性能,因为我有多个字符串序列,对于每个序列,我每次都必须迭代子字符串向量,我希望避免这种情况。使用lookaheads是可能的。现在告诉我们你尝试了什么?@georgiana_e在这种情况下,你可以尝试KMP算法的改进版本。您可以为每个可能的子字符串维护表,而不是1个表。当然,如果一个子串占主导地位,也可以通过第一检查子串的数量。首先,我想知道是否有可能编写C++ ReEX表达式,我可以说:我想在那个位置匹配这个。您确定这是正则表达式吗?我可以在字符串中最多200个字符。我不能把“?”放200次。我和已知的位置2,3,12混淆了。位置2,3,12代表起始位置。例如,substring1:“1100”位置1:2表示我希望匹配字符串中从位置2开始的“1100”。