python - Group m groups with regex -
i have regex replaces letter n (\w{1,}) -- meaning word can stand in letter n. want make group out of m instances of (\w{1,}) -- i.e add parens around m instances of (\w{1,}) , this: "(" + "(\w{1,}), (\w{1,}), (\w{1,}) .... (\w{1,})" + ")", (\w{1,}) occurs m times how can that? know like re.sub(\w{1,}){2,}, inputstring, "(" + many instances of (\w{1,}) pattern able match + ")) how express, in regex, pattern matched m times? (so can replace, surrounded parenthesis). if understand question correctly, you're writing 1 regex produce regex. is, you're using regex replacement build pattern regex search. input includes kind of wildcard value (e.g. "n" ) need replace create search pattern. in search pattern, adjacent wildcard values should combined single capturing group (so "n n bacon n" give 2 capturing groups, 1 first 2 words , 1 more last). think can if first capture adjacent wildcards, substitut