On Apr 17, 9:17 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Paddy schrieb: > > > > > On Apr 16, 10:50 am, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote: > >> Hi, I'm writing a program with a large data stream to which modules can > >> connect using regular expressions. > > >> Now I'd like to not have to test all expressions every time I get a line, > >> as most of the time, one of them having a match means none of the others > >> can have so. > > >> But ofcource there are also cases where a regular expression can > >> "contain" another expression, like in: > >> "^strange line (\w+) and (\w+)$" and "^strange line (\w+) (?:.*?)$" in > >> which case I'd like to first test the seccond and only if it mathces test > >> the seccond. > > >> Do anybody know if such a test is possible? > >> if exp0.contains(exp1): ... > > > you could OR all the individual RE's test them all at once then find > > out which matched. > > > big_re = "|".join( r"(?P<__match_%i__>%s)" % (i, r) > > for i,r in enumerate(regexps) ) > > > now if one of the regexps matches then the corresponding named > > group should have a non-empty string value. > > This doesn't answer the question if two of the sub-expressions matched. > > Diez
Or three, or four... If the frequencies of occurence are right and the OP wants all, then he could use the above to get any then follow up with a search for all the rest to the right of the matching regexp portion to get any more. But thats complex. Better to just do individual matches in a loop I'd think. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list