Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Nov 17, 2019 7:58 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 8:35 pm 
Offline

Joined: Sun Jun 24, 2007 1:40 pm
Posts: 559
Hi All,

I'm having an issue with a RegEx in a loop. Here is the code:

dim regHeadersCats as new RegEx
dim myRegExMatch as RegExMatch
dim arrHeadersCategories() as String
dim charLocation as Integer

regHeadersCats.Options.DotMatchAll = True
regHeadersCats.Options.TreatTargetAsOneLine = true

regHeadersCats.SearchPattern = "<h2 class=""items"">((?!</div>).)*</div>"

while charLocation < reqResult.Len
myRegExMatch = regHeadersCats.Search(reqResult,charLocation)

if myRegExMatch = nil then
exit while
end if

charLocation = myRegExMatch.SubExpressionStartB(0) + myRegExMatch.SubExpressionString(0).Len
ProcessHeaderCategoryGroup(vMGESearchCategory,myRegExMatch.SubExpressionString(0))

wend


For whatever reason, the loop will get to the 3rd iteration and crashes (without breaking) as it attempts to "Search" the 3rd time. However, this same code works in OS X. The purpose of this particular code, obviously, is to parse some HTML. Again, it works in OS X, but crashes without warning in Windows. I've tried on XP and Win2k systems. Is there perhaps some issue with RegEx iteration in Windows?

Hopefully there's something simple I'm missing.

Best.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 9:45 pm 
Offline

Joined: Mon Sep 22, 2008 9:01 pm
Posts: 61
Looking at your code i can see one potential problem, you should use LenB instead of Len, because SubExpressionStartB goes by the binary count of characters, so that will cause issues if not changed.

You can also try changing exit while to just exit, (maybe windows has problems with that, but probably not) lol not sure but worth a try.

I used regex a crapload in my windows software for a number of things and i don't think i've experienced a problem with it like you're explaining.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 10:32 pm 
Offline

Joined: Sun Jun 24, 2007 1:40 pm
Posts: 559
Thanks for the input. Unfortunately, that wasn't the fix. It's not even throwing an error. The application is just quitting. This is very odd.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 10:54 pm 
Offline

Joined: Mon Sep 22, 2008 9:01 pm
Posts: 61
what kind of app is it, console? desktop?


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 10:59 pm 
Offline

Joined: Sun Jun 24, 2007 1:40 pm
Posts: 559
Desktop application.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 11:18 pm 
Offline

Joined: Mon Sep 22, 2008 9:01 pm
Posts: 61
got some sample html you use for this?


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 11:22 pm 
Offline

Joined: Mon Sep 22, 2008 9:01 pm
Posts: 61
am unable to make it crash with the html im using, but i don't think my html has anything that matches ur search pattern, im also on windows 7 perhaps that's another reason... i don't know yet


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Sat Oct 08, 2011 11:38 pm 
Offline

Joined: Sun Jun 24, 2007 1:40 pm
Posts: 559
Yeah, I'm not sure what's going on. I've tried chopping, rearranging, doubling, tripling the file(s) I'm using and it always crashes on the 3rd iteration. The items I'm working on aren't "top secret", but I'd rather not reveal the files being parsed unless I'm sure it's absolutely necessary.

Regardless, if it doesn't match, it should simply exit. No? Does windows perhaps have issue with any text formatting? Should I be converting it or adding an encoding? Is there *anything* you can think of? The strange thing is, I'm performing a different RegEx loop prior to this one and it works just fine, regardless of size/arrangement. Perhaps there is an issue with the 'look-behind' I'm doing in this particular RegEx? Maybe there's a better way to find what I'm looking for. :(

I absolutely appreciate your input thus far. No worries if you can't find anything.


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Mon Oct 10, 2011 3:32 am 
Offline

Joined: Mon Jul 24, 2006 4:06 am
Posts: 274
Some time ago I managed a nice crash with Regex on Mac OS [url]<feedback://showreport?report_id=18229>[/url]. So regex is not without problems. Can't Windows do crash logs? Can you post the html?

By the way, regex and html are a really bad idea.

_________________
Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com
Mail Archiver X: The email archiving solution for professionals


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Mon Oct 10, 2011 2:47 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Wouldn't a better way to code the loop be
myRegExMatch = regHeadersCats.Search(reqResult)
while myRegExMatch <> nil
ProcessHeaderCategoryGroup(vMGESearchCategory,myRegExMatch.SubExpressionString(0))
myRegExMatch = regHeadersCats.Search
wend


Top
 Profile  
Reply with quote  
 Post subject: Re: RegEx inside loop crashes application in Windows.
PostPosted: Mon Oct 10, 2011 4:20 pm 
Offline

Joined: Sun Jun 24, 2007 1:40 pm
Posts: 559
timhare wrote:
Wouldn't a better way to code the loop be
myRegExMatch = regHeadersCats.Search(reqResult)
while myRegExMatch <> nil
ProcessHeaderCategoryGroup(vMGESearchCategory,myRegExMatch.SubExpressionString(0))
myRegExMatch = regHeadersCats.Search
wend


Well my goal isn't to be "greedy" with the process, but rather, to find each and every instance of the match while moving down through the HTML. AFAIK, the only way to do that is to increment a positional counter and start from your last match.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group