Deye Posted June 2, 2018 Share Posted June 2, 2018 Hi, What can be the shortest way to return (3) when passing "Wesley" or "Ingrid" (both in group 3) using StringRegExpReplace ? Other names are not shortened for this no do example : $iGroup = StringRegExpReplace("Wesley", ' "Renee,Eero,Maverick", "Chase,Seth,Sean", "Leonora,Wes,rid", "Jacob,Ashley,Rocket" ', ' 1.2.3.4 ') MsgBox(0, "", "Wesley is in group - " & $iGroup Thanks Link to comment Share on other sites More sharing options...
TheXman Posted June 2, 2018 Share Posted June 2, 2018 Can you try to explain, in more detail, what it is you are trying to accomplish? Also, please explain why the StringRegExpReplace function is so integral to the solution. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
jchd Posted June 2, 2018 Share Posted June 2, 2018 This works: Local $sPattern = "^.*?(?:(Renee|Eero|Maverick)|(Chase|Seth|Sean)|(Leonora|Wes|rid)|(Jacob|Ashley|ocke)).*" Local $sReplace = "('$1'=''?0:1)+('$2'=''?0:2)+('$3'=''?0:3)+('$4'=''?0:4)" Local $iGroup = Execute(StringRegExpReplace("Wesley", $sPattern, $sReplace)) MsgBox(0, "", "Wesley is in group - " & $iGroup) $iGroup = Execute(StringRegExpReplace("Ingrid", $sPattern, $sReplace)) MsgBox(0, "", "Ingrid is in group - " & $iGroup) $iGroup = Execute(StringRegExpReplace("Rocket", $sPattern, $sReplace)) MsgBox(0, "", "Rocket is in group - " & $iGroup) Deye 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Deye Posted June 2, 2018 Author Share Posted June 2, 2018 TheXman, thanks for your response, I have chosen StringRegExpReplace as the candidate for this, simply because i know it deals with expressions and replacements for any needed modded returns ,one liner approach ,no arrays ,etc. , I only needed this example on how it can be done, wiz style jchd, Thanks I appreciate it, fits precisely with what i had in mind Link to comment Share on other sites More sharing options...
mikell Posted June 2, 2018 Share Posted June 2, 2018 Well, it will work nicely as long as there is no "rid" (for Ridley) in another group Deye 1 Link to comment Share on other sites More sharing options...
Deye Posted June 2, 2018 Author Share Posted June 2, 2018 I honestly forgot to mention that if i for instance passed "ridge" it should return 3 as well Link to comment Share on other sites More sharing options...
jchd Posted June 3, 2018 Share Posted June 3, 2018 While in the proposed code the pattern may be easily derived from small-size input data, this "solution" is highly sensitive to possible collisions, as @mikell pointed out. If the input is likely to be(come) much larger I'd recommend a completely different approach. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Deye Posted June 7, 2018 Author Share Posted June 7, 2018 and so the plot thickens .. what can be changed to make it always look for the first match Having "dge" in a group before or after "Rid" it always resolves to the "Rid" group .. Local $sPattern = "^.*?(?:(Renee|Eero|dge)|(Chase|Seth|Sean)|(Leonora|Wes|Rid)).*" ;~ Local $sPattern = "^.*?(?:(Leonora|Wes|Rid)|(Chase|Seth|Sean)|(Renee|Eero|dge)).*" Local $sReplace = "('$1'=''?0:1)+('$2'=''?0:2)+('$3'=''?0:3)" Local $iGroup = Execute(StringRegExpReplace("Ridge", $sPattern, $sReplace)) MsgBox(0, "Ridge", "Ridge is in group - " & $iGroup) Link to comment Share on other sites More sharing options...
jchd Posted June 7, 2018 Share Posted June 7, 2018 That's precisely the fail case for this approach: unwanted collisions (as I just above). Still you can mitigate some of these issues: Local $sPattern = "^.*?(?:(Renee|Eero|.*dge)|(Chase|Seth|Sean)|(Leonora|Wes|Rid)).*" Local $sReplace = "('$1'=''?0:1)+('$2'=''?0:2)+('$3'=''?0:3)" Local $iGroup = Execute(StringRegExpReplace("Ridge", $sPattern, $sReplace)) MsgBox(0, "Ridge", "Ridge is in group - " & $iGroup) Deye 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Deye Posted June 7, 2018 Author Share Posted June 7, 2018 jchd, guess I somehow got over occupied to not think of trying that out for myself - no biggie Thanks again 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