Hi,
Is it possible to get the string after a text in a variable that states ‘our ref’ I would want the text after the string our ref as I want to save that string as a KM variable.
e.g. I have a variable named ‘content’ inside this variable the following text is stored: some text Our ref: 1548797 …more text
I would want to automatically locate the string after ‘Our ref:’ which is ‘1548797’ and save that as a KM variable and maybe upto he next 5 characters after 1548797* ends…
Thank you very much it works, but it does not pick up when I have a hyphen in the reference such as 1545-445 i get the result 1545445 instead. Sometime the variable may have ‘/’ or letters inside of it too. Whats the best way to do this?
Dan, scansnap scans from KM, then saves the letter as OCR. KM then reads the letter without opening it and saves the text of the letter as a variable. We now need to grab the references. What would you say is the best way to handle these references?
generally the references are on the same line. Sometimes the gap can be more than 2 spaces......
Here are the non OCR versions of the refs that we scan.
Regular expressions (RegEx or RegExp) are extremely powerful, but have an initial steep learning curve that is often intimidating. But once you get over that initial hump, and you continue to write new RegExp, it will become much easier.
You should also know that there are often many ways to write a RegEx to achieve the same results. Most of the time it does not matter, unless the source text is very long, and the RegEx is very complex.
I do all of my RegEx development at this free website:
Here are some examples, I am having a lot of dificulty trying to get a one size fits all approach. Do you have any suggestions how I can approach this? generally the ref is on the same line and it is rare that something else is on the same line but it does happen. When it does happen there is a large space before the next writing commences.
Our reference; A4846408
Our reference: A4846408
O u r r e f e r e n c e : 3 - 4 7 1 9 8 0 3 1 7
Our reference : 3-471980317
O u r R e f : P P I / 3 8 7 6 1 3 1
Our Ref: PPI/3876131
Our reference: 3-471980407
Re: CPPI5506 Claim PPI/957188/1518413978
Our ref no: SAR Team/TG - 860384
O u r r e f e r e n c e : 3 - 4 7 1 9 8 0 4 1 3
O u r R e f U 6 0 1 8 9 0
Our Ref U601890
Our Ref; 3935878
Our Ref: 3935878
Ou r R e f ; 3 9 3 5 8 7 8
O u r R e f : 3 9 3 5 8 7 8
O u r r e f e r e n c e : 3 - 4 7 1 9 8 0 4 0 4
R e f e r e n c e C O M / 3 3 4 5 3 3 / 2 0 1 6
Reference COM/334533/2016
something like this works but it does not cover all elements, is it even possible to cover all in one? also the dots only work if the string matches if i add more dots than the string the result is then blank. I guess using the dots is not a good idea.
I’m sure other people will disagree with me, and I’ll give my reasons in a moment.
But I think the only sure and easy-to-maintain way is what you’re doing, except I’d use a “Switch” action. You can have all sorts of conditions, regexes, etc. And use an “otherwise” condition at the end, so you can display a message if none of the conditions match.
Let me know if you need help with it.
Now here’s my reasoning.
First off, while it might be possible to develop a few regexes to handle all the conditions, they’d probably be fairly complex. Which means, the first time they don’t match something, you have to figure out why, and either fix them (without breaking them) or craft another one. This might be OK if you’re a regex expert, but I still wouldn’t recommend it.
I’ve been developing professionally since 1979. I always want to overengineer everything. Because it feels good to have some small, tight bit of code. But then it breaks. And you can’t figure out how to refactor it to handle this new issue. And you spend forever on it.
It’s so much easier to have a long switch statement. While it looks ungainly, it’s a snap to add a new condition. And trust me, when you’ve been using the macro for a while, and it suddenly breaks, you’ll be incredibly happy that it’s so simple to understand.
Mind you, I’m not saying you can’t use some regexes. Just don’t try to handle everything in one of them. It will take time at the start, but as I said, it’s time you’d spend (and them some) trying to figure it out later.