erifash Posted June 23, 2005 Share Posted June 23, 2005 (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 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! 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 June 23, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
erifash Posted June 24, 2005 Author Share Posted June 24, 2005 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? 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! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
w0uter Posted June 24, 2005 Share Posted June 24, 2005 (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 June 24, 2005 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 Link to comment Share on other sites More sharing options...
erifash Posted June 24, 2005 Author Share Posted June 24, 2005 (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 June 24, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
w0uter Posted June 24, 2005 Share Posted June 24, 2005 you mean a pattern like this $start & '(.*?)' & $end but if like $start is *test\s then your screwed My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
erifash Posted June 24, 2005 Author Share Posted June 24, 2005 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. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now