I'm trying to do a non-greedy pattern match using Regex to get a 3-6 digit order number.
The standard PCRE Search Pattern is:(Order No)(.*?)(\d{3,6})
Then I get the order number using $3 (or \3 for Switch)
The problem is .*? in Switch is greedy and so it grabs everything to the end of the file/string.
So, is there a way to restrict the search after 'Order No' to "any amount of any characters up to the next 3-6 digit integer?"
Many thanks, Pat
Non-Greedy Pattern Matching
Re: Non-Greedy Pattern Matching
Could you describe where you are doing this matching? Perhaps take a screenshot of where you are putting your current search pattern. The answer could go a few different ways depending on if this is within the variable builder in Switch, Scripter, or elsewhere.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Newbie
- Posts: 6
- Joined: Mon Jul 06, 2015 10:56 pm
Re: Non-Greedy Pattern Matching
Thanks for the reply.
I have been trying to do this in a variable builder within a flow. It examines a 'body' node from an 'Email' metadata set.
An example of the string it would try for the pattern match within:
Order No</span></b><span style="font-size: 9pt;" class=""><span class="Apple-converted-space"> </span>033174<
My main interest is in knowing if there is standard method in Switch of doing any any character non-greedy match, as I've stumbled on this before.
I have been trying to do this in a variable builder within a flow. It examines a 'body' node from an 'Email' metadata set.
An example of the string it would try for the pattern match within:
Order No</span></b><span style="font-size: 9pt;" class=""><span class="Apple-converted-space"> </span>033174<
My main interest is in knowing if there is standard method in Switch of doing any any character non-greedy match, as I've stumbled on this before.
Re: Non-Greedy Pattern Matching
Hi,
What about this : \d{3,6}$
That would catch any 3-6 numbers at the end of a string. If you need to ensure that it's not a false positive, you can filter the whole match first.
HTH
Loic
www.ozalto.com
What about this : \d{3,6}$
That would catch any 3-6 numbers at the end of a string. If you need to ensure that it's not a false positive, you can filter the whole match first.
HTH
Loic
www.ozalto.com
-
- Newbie
- Posts: 6
- Joined: Mon Jul 06, 2015 10:56 pm
Re: Non-Greedy Pattern Matching
Thanks loicaigon - however the integer isn't at the end of a line, so it won't match.
-
- Newbie
- Posts: 6
- Joined: Mon Jul 06, 2015 10:56 pm
Re: Non-Greedy Pattern Matching
We found a solution.
In the end, we went with a Script and used this pattern to match the required string:
The trick was to find something consistent *after* the required string, and we had "(Sequential ID)" to match against
With that we were able to get the integer after the html span tags and pick out the 4th group using:
Thanks for the help!
In the end, we went with a Script and used this pattern to match the required string:
Code: Select all
var regExEmailBody = /(Order No)(.*)(\/span\>)([\d]{3,6})(.*)(Sequential\sID)/;
With that we were able to get the integer after the html span tags and pick out the 4th group using:
Code: Select all
var orderID = regExEmailBody.capturedTexts[4];