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

Question

Question

Regex for String that ends with three possible variations

asked on June 23, 2022 • Show version history

I've put together a regex that works in test environments (like regex101.com), but when I try to use it in Laserfiche I get a completely different result.

I'm looking to identify schools, and the schools all end with "Elementary", "Middle", or "Secondary"

"[A-Za-z '-.]*[A-Za-z'-.]\s+([Ee]lementary|[Mm]iddle|[Ss]econdary)"

 

So, for example on regex101, that regex identifies the string "John Wayne Middle" perfectly.  However, in Laserfiche (when I use "Test the Pattern" or when I run a sample page through) it only resolves the word "Middle" from "John Wayne Middle".

 

 

Am I doing this wrong, doing this wrong in the world of Laserfiche, or is this just not how Laserfiche parses regex commands and I'm doomed to failure?

0 0

Replies

replied on June 23, 2022 • Show version history

The parenthesis are saying "return only what is in here" which is why you are only getting the word Middle when searching John Wayne Middle.

When I test on regex101 that's what I see there too:    See how Middle is flagged in green but the rest is not?

Perhaps try something like this:  

[A-Za-z '-.]*\s+[Ee]lementary|[A-Za-z '-.]*\s+[Mm]iddle|[A-Za-z '-.]*\s+[Ss]econdary

Which is saying:
[A-Za-z '-.]*\s+[Ee]lementary
OR
[A-Za-z '-.]*\s+[Mm]iddle
OR
[A-Za-z '-.]*\s+[Ss]econdary

And seems to be working in my testing in Workflow.

1 0
replied on June 23, 2022

Ok, I think I have it.  Not exactly sure why I had to jump through the extra hoops, but:

 

[A-Za-z '-.]*[A-Za-z'-.]\s+(?:(?:[Ee]lementary|[Mm]iddle|[Ss]econdary)$)

 

If I read this correctly, I've put a Non-capturing group in a non-capturing group.  But I hadn't marked the end of the input before, so maybe that's it?

0 0
replied on June 23, 2022 • Show version history

Weird, your original regex works for me:

Edit: Oh, wait, you're saying you want to read the "John Wayne" part, aren't you? That's because of the parentheses. They mark what you want extracted from the input value.

0 0
replied on June 23, 2022

@████████ they got the same result as you.  They want the whole school name.  The capture group in the original is only for the last word "Elementary", "Middle", or "Secondary".

2 0
replied on June 23, 2022

Exactly, but the updated regex seems to work.

 

0 0
replied on June 23, 2022

You only needed to turn the original capture group (parentheses) into a non-capturing group (question-colon parentheses).  I tested this and it works as desired. 

Why do you think you need nested non-capturing groups and the end-of-input anchor? In particular, having the end-of-input character could cause a match failure in some circumstances that you'd expect it to succeed (e.g., if there is any text after "Middle").

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

Sign in to reply to this post.