Capture string in between two given string

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Niroj@Work
Pro Scripter
Posts: 63
Joined: Thu Dec 10, 2009 8:13 am

Post by Niroj@Work » Fri Apr 30, 2010 6:33 am

Also I am tired using the RegEx command in my program. Sometimes the the error message "Regular Pattern matching does not compile" is getting displayed in run time. God knows for what it is displaying? Especially while running the Exes it is really hard to debug it. Though I am not able to debug it but may be this is due to some special text like commas coming dynamically in RegEx matching in the source text.

Whatever may be the text coming or passed to the RegEx command it should not show this error message since I am not violating the syntax for the searching pattern(I made the pattern fixed) and I don't have any control over the coming text which is actually being captured from a screen.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Apr 30, 2010 3:25 pm

Hi Marcus,

I know the v12 release is keeping you pretty busy... but is there any chance you could look into the problem below?
mtettmar wrote:
jpuziano wrote:Interesting... I tried the following:

Code: Select all

Let>str=abcd %CRLF% hhjh jhj {select hgh %CRLF% hh=!3j h %CRLF% jh ? }jdjk jdkj jkj %CRLF% {nb bb hjdh %CRLF%%CRLF% nb jkj}%CRLF%

Let>pattern=({.*?)\r\n(.*?)\r\n(.*?})

RegEx>pattern,str,0,match_array,num,1,$1%~$2~$3,new_string

MDL>new_string
However it fails with the error: Regular Expression pattern not compiled.

I'm not sure why though, maybe Marcus can shed some light.

Even if the above error could be eliminated though, I am not sure if this would catch and change multiple occurances of %CRLF% within { and } chars... it might only catch the first or last occurance within any { and } pair.

You can do this brute force with procedural code of course... but I am thinking you're looking for a regex solution here.

Marcus or anyone else, please jump in.
Seems to only happen if the replace flag is set. If not replacing there is no error. I'm not sure why. I have put it on the to do list and will investigate.
Finding a fix for this one may also fix the problems that Niroj@Work is running into... they sound similar.

Take care
Last edited by jpuziano on Fri Apr 30, 2010 8:57 pm, edited 1 time in total.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Fri Apr 30, 2010 8:36 pm

I don't get the compile error if I set the EasyPatterns flag to 1.
I did not use brackets [...]

Code: Select all

Let>str=abcd %CRLF% hhjh jhj {select hgh %CRLF% hh=!3j h %CRLF% jh ? }jdjk jdkj jkj %CRLF% {nb bb hjdh %CRLF%%CRLF% nb jkj}%CRLF%

Let>pattern=(?<={.+?)\r\n(?=.+?})

RegEx>pattern,str,1,match_array,num,1,~,new_string

MDL>new_string


This should not be the syntax, but it seems to work.


Gale

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Jul 08, 2010 9:25 pm

gdyvig wrote:I don't get the compile error if I set the EasyPatterns flag to 1.

This should not be the syntax, but it seems to work.
Gale
Thanks Gale for posting your findings above.

Marcus, have you had any time to look further into this error and why it is produced?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 09, 2010 10:01 am

The problem is that the pattern is not a valid PCRE expression.

Put the pattern into RegExBuddy using the PCRE engine and it highlights the first +? saying:

The PCRE library does not support infinite repetition inside lookbehind

And if we remove it from the pattern so that we end up with:

(?<={.)\r\n(?=.+?})

Then we get no error.

But before anyone says anything, yes, I agree the error message produced by the regex engine that Macro Scheduler is using is not entirely helpful. I guess it just can't make sense of the pattern so gives a compile error.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Oct 31, 2011 10:51 pm

mtettmar wrote:Seems to only happen if the replace flag is set. If not replacing there is no error. I'm not sure why. I have put it on the to do list and will investigate.
Hi Marcus,

Can you update us on this one? Was a fix found or...?

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts