Sign in to follow this  
Followers 0
erifash

RexExp Question

6 posts in this topic

#1 ·  Posted (edited)

I am (still :) ) a noob to RegExp and was wondering (based off Insolence's reply)

Eh, regexp is probably a bit faster.  If this was introduced before, it would've been much more appriciated :D

Good idea, bad timing.

<{POST_SNAPBACK}>

how a string parser using RegExp could be better than my string parser (_Parse) that uses only four lines of code and two StringSplits? Surely mine has flaws (such as not returning if it succeeded or not) but can someone show me a good example of a string parser using RegExp that does not require a pattern from the user and can be used for different types of strings (such as html, plain text, user input, etc...)? I would really appreciate if some regexp guru could show me the way! :evil:

Also, if you don't have it, here is my parsing function:

Func _Parse($sz_str, $sz_before, $sz_after)
    Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1), $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1)
    Return $sz_sp2[1]
EndFunc  ;==>_Parse()
Edited by erifash

Share this post


Link to post
Share on other sites



Wow, this topic died really fast. I'm surprised no ne has answered! So, i'm guessing, that no one knows how to do this? :evil: It didn't even get one reply! If someone shows me a better way to do what I did in _Parse() only with RegExp i'll give them a cookie! :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

[edit]

_Parse is better then using regexp for the job since the special characters must all be prefixed with escapes. this will take way to long so _Parse would be better.

[/edit]

[edit2]

made this. AFAIK this is faster.

Func _Parse1($sz_str, $sz_before, $sz_after)
    Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1), $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1)
    Return $sz_sp2[1]
EndFunc;==> _Parse1()

Func _Parse2($sz_str, $sz_before, $sz_after)
    Return StringMid($sz_str, StringInStr($sz_str, $sz_before) + StringLen($sz_before), StringInStr($sz_str, $sz_after) - StringLen($sz_after) - 1)
EndFunc;==> _Parse2()



$t = TimerInit()
For $i = 0 To 100
    _Parse1('this is a test', 'this', 'test')
Next
ConsoleWrite(TimerDiff($t) & @LF)

$t = TimerInit()
For $i = 0 To 100
    _Parse2('this is a test', 'this', 'test')
Next
ConsoleWrite(TimerDiff($t) & @LF)

[/edit2]

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wow, this is great! Thanks w0uter!

You get a cookie. :)

Also...

_Parse is better then using regexp for the job since the special characters must all be prefixed with escapes. this will take way to long so _Parse would be better.

<{POST_SNAPBACK}>

... I knew it! You would need to create a pattern for each different string if you used RegExp as a string parser, which would take way too long to do based off user input. Plus it would take more lines to accomplish that than w0uter's three line translation of my string parsing function. Thanks for that! Edited by erifash

Share this post


Link to post
Share on other sites

Exactly what I was saying about the different types of strings. To mak it truly a string parser, the code would need to generate it's own pattern so the user wouldn't have to. Then what would the point be of a script with over 70 lines that takes more than 10 seconds to parse versus a three line script that takes bare milliseconds to parse? I'm not sure if a script can even recognize a pattern within any type of string like that. If it can, then there's always the chance that it will mess up. It's really a dead-end. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0