Regular Expression Matching all permutations [closed]


I want to find all the permutations of 0123 in the string below 01210210021212333212300213231102023103130001332121230221000012333333021032112

can i have a regular expression that can give me the permutations of 0123 matching in the string ? Also i need if there are any overlapped patters

"0123" here i want a match of [1023][1230][2301][3012]


Not regex, but C++11:

#include <iostream> #include <algorithm> #include <string> int main() { const std::string s("01210210021212333212300213231102023103130001332121230221000012333333021032112"); const std::string ref("0123"); if(ref.length() > s.length()) { return 0; } for(int i = 0; i < s.length() - ref.length(); ++i) { if(std::is_permutation(s.cbegin()+i, s.cbegin()+i+ref.length(), ref.cbegin())) { const std::string extract(s, i, ref.length()); std::cout << extract << std::endl; } } return 0; }

To be compiled for example with g++ -std=c++11 -o sample sample.cpp

If you absolutely need regex: (?=[0123]{3})(.)(?!\1)(.)(?!\1|\2)(.)(?!\1|\2|\3). which means:

(?=[0123]{3}) : positive assertion that the 4 next characters are 0, 1, 2, 3 (.) : capture first character (?!\1) : assert that following character is not the first capture group (.) : capture second character (?!\1|\2) : assert that following character is neither the first nor the second capture group etc.


A regular expression cannot do what you're asking for. It cannot generate permutations from a string.


  • C++ String tokenisation from 3D .obj files
  • Regex for nested values
  • How gzip file gets stored in HDFS
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Efficient User-Agent Regex to find Safari in Python
  • Building Qt project for C++11 standard
  • C++ friend class std::vector
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • C: Incompatible pointer type initializing
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Time complexity of a program which involves multiple variables
  • one Local Olampyad Questions on Informatic in 2011
  • Meteor helpers not available in Angular template
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Regex thinks I'm nesting, but I'm not
  • AES padding and writing the ciphertext to a disk file
  • VS2008 Enable C++ Exception with SEH
  • output of program is not same as passed argument
  • MySQL WHERE-condition in procedure ignored
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Akka Routing: Reply's send to router ends up as dead letters
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • Checking variable from a different class in C#
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal