Hi,
My regex is: (.*?\\|)(.*?\\|)(.*?\\|)(.*?\\|)(.*?\\|)(.*?\\|)(?:.*?\\|)(.*?\\|)(.*?\\|)(?:.*?\\|)(.*)
so I have 9 matching groups.
How do I shorten this and reuse the (.*?\\|). I tried: (.*?\\|){6}(?:.*?\\|)(.*?\\|){2}(?:.*?\\|)(.*) but it doesn't give me the 9 matching groups.
Thanks,
When you reduce the number of capture groups that is the result.
Please provide source text and desired matches if you would like additional assistance.
This is how I would reuse that match group pattern based on your example:
(.*?\\|)((?1))((?1))((?1))((?1))((?1))(?1)((?1))((?1))(?1)(.*)
abc|abc|abc|abc|abc|abc|xxxxxx|abc|abc|zzzzzzzzzz|sdfjashdipfhaeofhaopsdfhabcwejsopfjpsdfj
so if I apply my regex on this string and concatinate the 9 groups I'll just lose the x's and the z's in the middle
Confirm you want the resulting string to be:
abc|abc|abc|abc|abc|abc|abc|abc|sdfjashdipfhaeofhaopsdfhabcwejsopfjpsdfj
Raw Match Pattern:(([^|]*\|){6})(?2)((?2){2})(?2)(.*)
Concatenate groups 1, 3, 4.
or:
Raw Match Pattern:((?:[^|]*\|){6})[^|]*\|((?:[^|]*\|){2})[^|]*\|(.*)Concatenate groups 1,2,3.
Double \'s as required by your platform (i.e. Java).