iOS Shortcut, regex match these words, while excluding these words
I am using iOS Shortcuts and am using it get contents of page (converts the page to RTF), then running through make text to turn it into plain text.
I am trying to develop an IUC flavored regex to search for key words/phrases on a list of pages I am looping over with a while each, but want the regular expression to exclude other phrases and prevent a false-positive trigger.
I have it set up with two capture groups. I’m not sure if it is desired to make the second group a non-capture group, or not attempt capture at all. I only think the second one must be either a capture, or non-capture group for the logical AND provided. I read that (this)(that) acts as an and, but I’m not sure if either is a negate, whether it follows that logic. For that reason, I’m not sure if the negate should not be it’s own capture group, non-capture group, or shouldn’t be using the brackets at all. I had tried some nested capture group stuff, but that seems to not follow the syntax.
Currently, I have tried a wide variety of regular expressions. I do not have a full list, but I can share a few permutations I have tried starting with the most recent:
(?>IncludesTermsOne|IncludesTermsTwo|IncludesTerms3)(?:<!ExcludesTermsOne|ExcludesTermsTwo|ExcludesTerms3)
(?IncludesTermsOne|IncludesTermsTwo|IncludesTerms3)^(?!ExcludesTermsOne|ExcludesTermsTwo|ExcludesTerms3)
Just to be clear, I want it to first search the exclude terms and fail if it finds one. Then if it doesn’t find any of these negate terms, then begin searching through the include terms. It is fine that the include list and exclude list terms, respective to each grouping are being treated on an OR basis (per piping |) as that is the intended behavior I’m seeking. Finally, I am wanting to start my search at the top of the page and for it to stop searching / attempting capture in this logical order:
- Exclude term found, STOP
— First include term found, STOP
Final note, this search is obviously performed over multiple lines. I am only seeking to capture the include term, not the exclude term. I only want the exclude term to cancel out a match of both exist (either before or after – cross directionally). That is if an exclude term exists, negate the positive term and provide zero matches.