Copy link to clipboard
Copied
Hey folks, very simple grep question. I can't quite crack it through my own attempts of lookbehinds/aheads.
I want to get any of the following when it occurs within parentheses, regardless of position as long as it's within parentheses, but I do not want to include the parentheses.
Any ideas?
Terms to search for (I am listing like this for ease; I know the or operator):
Genesis
Exodus
Leviticus
Numbers
Deuteronomy
Joshua
Judges
Samuel
Chronicles
Psalms
Proverbs
Ecclesiastes
Song of Songs
Canticles
Isaiah
Jeremiah
Lamentations
Ezekiel
Daniel
Hosea
Obadiah
Jonah
Micah
Nahum
Habakkuk
Zephaniah
Haggai
Zechariah
Malachi
Matthew
Romans
Corinthians
Galatians
Ephesians
Philippians
Colossians
Thessalonians
Timothy
Titus
Philemon
Hebrews
James
Peter
Revelation
Copy link to clipboard
Copied
One way to achieve this effect is by the use of positive lookaheads and lookbehinds. If you're new to regular expressions, they might be unfamiliar to you. It's a way to say "match anything that appears right after an open-parenthesis, and right before a close parenthesis, but don't match the parentheses." They look like this:
(?<=\()(All|your|biblical|search|terms|go|here)(?=\))
So, the first group is a positive lookbehind.
( ) group enclosed by parentheses
?<= match the expresssion if the search terms are immediately preceeded by
\( an actual open-parenthesis in the text you're searching
You have to escape the parenthesis you're looking for, because the GREP syntax uses parentheses to group parts of your query, so put a backslash in front of your open parenthesis in your GREP query.
The second group is where you put your books of the Bible, separated by many OR statements
The third group is a positive lookahead:
( ) group enclosed by parentheses
?= only match whole expresssion if the terms are immediately followed by
\) an actual close-parenthesis in the text you're searching
This query should find any book of the Bible enclosed by parentheses, without matching the parentheses
Copy link to clipboard
Copied
Joel - thanks, but this doesn't quite do what I need. I need to highlight it regardless of position as long as it's within parentheses. This means that if Matthew is preceded by anything (such as another biblical reference, if it's one in a string of biblical references in the same set of parentheses; or perhaps an index marker ~I), it will still get selected as long as it's within the parentheses.
Copy link to clipboard
Copied
Well, I didn't get that from the phrase "regardless of position" but I think I get what you're looking for now. That's down to my own lack of reading comprehension, I think.
Are you looking for:
Open parentheses
Followed by
Zero-or-more characters that are neither books-of-the-Bible nor close-parentheses
Followed by
Your book-of-the-Bible query
Followed by
Zero-or-more characters that are neither books-of-the-Bible nor close-parentheses
Followed by
Close parentheses
And you want this query to return 100% of the text within the parentheses, right?
I'm on my phone so it's not easy for me to check how well it works within InDesign but I bet it'd look like this:
(?<=\()(.*)(All|your|biblical|search|terms|go|here)(.*)(?=\))
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The second (.*) should be (*?) (add a question mark).
Copy link to clipboard
Copied
It still isn't working.