You are viewing limited content. For full access, please sign in.

Question

Question

Quick Fields - Pattern Matching assistance

asked on September 22

Hello,

I need some help with a regular expression again. In the two images attached, I need to grab the paragraph beneath the first line, but before either the word "Section" or "Whereas." So the paragraph that starts with "an ordinance" is what I need. So essentially I'm looking for that ordinance number at the top, then I want to capture that paragraph of text, and when I see the word "section" or "whereas," I want to stop. Does that make sense?

Any help is appreciated. Thanks!

ordinance section.png
ordinance whereas.png
0 0

Replies

replied on September 22

I believe you want something like the following:

(.*?)(?:WHEREAS|SECTION)

And make sure you check the "Case sensitive" checkbox or else it does fun things like stop at "Section 403.19" in the WHEREAS example.

This pattern assumes that the WHEREAS and SECTION markers will always be uppercase and that those words will never appear capitalized within the paragraph above them.  Things get more complicated if that's not the case...


Here's a quick explanation of the pattern:

  1. The first set of parentheses says "this is the part I care about"
  2. The . means any character and the quantifier *? says "0 ore more, but lazily instead of greedily" (meaning it'll capture as little as possible where the pattern still matches instead of trying to grab as much as possible while still matching the pattern, which is the default for a * quantifier)
  3. The (?: ) parentheses are a non-capturing group, meaning we need them for an expression (an alternation in this case) but don't actually care about them otherwise.
  4. And inside those parentheses is a simple alternation, meaning look for THIS word or THAT word.
0 0
replied on September 22

You can try this, more specific in that it looks for ORDINACE No and then finds what is after

 

(?s)(?:ORDINANCE\s+NO\.\s+\d+)(.*)(?:WHEREAS)|(?:ORDINANCE\s#\s\d+)(.*)SECTION

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.