Jump to content

StringRegExp in Groups


Recommended Posts

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

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.

Link to comment
Share on other sites

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)

 

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 here
RegExp tutorial: enough to get started
PCRE 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


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

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 here
RegExp tutorial: enough to get started
PCRE 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

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

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)

 

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 here
RegExp tutorial: enough to get started
PCRE 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...