# [RESOLVED] RegEx Resource

## 5 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm back to working on my RegEx skills and trying to come up with something to reformat file directory / file paths that are coming from other applications so that I can feed the resulting list into another script that I came up with. My problem is that I have been testing my RegEx by using https://regex101.com/ with PCRE(PHP). To date it has worked well for me, however, I have hit a stumbling block. In the example below the RegEx on line 158 when applied to pattern "C:\S\*" should pass through the ELSE on line 162 and then get trapped by line 175.

Instead, it flows to 159 and then 188. I'm going cross-eyed and I can't spot the problem in the RegEx, If you have a moment and have experience with this kind of thing, would you please take a quick look and tell me what you think is wrong besides this being probably the ugliest way to go about a simple task.

The task is simply end up with either a full file path or a directory without a trailing backslash. Thanks in advance,

Casey

EDIT - [RESOLVED]  Replaced script block with corrections, though I am not at all happy with how sloppy it is and I am going to rewrite after learning quite a bit in the process. I just didn't want to leave a truly broken bit out here on the site.

```#include <Array.au3>
#include <Constants.au3>
#include <MsgBoxConstants.au3>

; Where we have a full path to a file including file extension
Local \$aArray[1] = ["C:\S\File.txt"]

; Where the training backslash is missing from a directory - This is good, DirGetSize format

; Where the training backslash exists on a directory - This is bad, DirGetSize won't work

; Where the path ends in an * - This is bad, DirGetSize value less than C:\S

; Where the path ends in an *.* - This is real bad, DirGetSize won't work and attrib is a laundry list

_ArrayAdd(\$aArray, "C:\Program Files (x86)\No Problem\*.*")
_ArrayAdd(\$aArray, "C:\Program Files (x86)\No Problem\*.txt")
_ArrayAdd(\$aArray, "C:\Program Files (x86)\No Problem\a.txt")

;========================================================================================================================================

; A must as we are working with Winternal's Process Monitor Output and Handles.exe Output
Local \$bArray = _ArrayUnique(\$aArray)

_ArrayColInsert(\$bArray, 1)
_ArrayColInsert(\$bArray, 2)

_ArrayDisplay(\$bArray, "Array @ Beginning")

;========================================================================================================================================

\$Cnt = 0
For \$i = 0 To UBound(\$bArray) - 1
\$Cnt = \$Cnt + 1
Next
\$Cnt = \$Cnt - 1

For \$i = 1 To \$Cnt

Local \$LenRegEx = 0
Local \$LenArrayItem = 0

;Test for something that might look like a file extension, greedy, but length of file extension and composition is unknown

Global \$cArray = StringRegExp(\$bArray[\$i][0], "^\w:\\[\. \( \) \w \\ \-]+\\[\w \\ \.-]+", 2)
If @error <> 0 Then
;_MsgBox("FIRST REGEX FAILED AND SET ERROR" & @CRLF & @CRLF & "\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$cArray = StringRegExp(\$bArray[\$i][0], "^\w:\\[\. \(\)\w\\\-]+\\[^\w \\ -]+", 2)
If @error <> 0 Then
Local \$LenRegEx = 0
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox("SECOND REGEX FAILED AND SET ERROR" & @CRLF & @CRLF & "\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$bArray[\$i][2] = @ScriptLineNumber
Else
Local \$LenRegEx = StringLen(\$cArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$bArray[\$i][2] = @ScriptLineNumber
EndIf
Else
Local \$LenRegEx = StringLen(\$cArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$bArray[\$i][2] = @ScriptLineNumber
EndIf

If \$LenRegEx == \$LenArrayItem Then
;_MsgBox("Some are FileGetSize and DirGetSize Compatible " & @CRLF & @CRLF & \$bArray[\$i][0] & @CRLF & @CRLF & \$cArray[0])
\$bArray[\$i][2] = @ScriptLineNumber

\$IsThereAnAsterixOrSlash = StringMid(\$bArray[\$i][0], \$LenArrayItem, 1)

;_MsgBox("\$IsThereAnAsterixOrSlash = " & \$IsThereAnAsterixOrSlash)
\$bArray[\$i][2] = @ScriptLineNumber

Select
Case \$IsThereAnAsterixOrSlash = "*"

If StringMid(\$bArray[\$i][0], (\$LenArrayItem - 1), 2) = "\*" Then
;_MsgBox("A \* existed " & StringLen(\$bArray[\$i][0]))
\$bArray[\$i][2] = @ScriptLineNumber
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], 2)
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
Else

\$IsItAsterixDotAsterix = StringMid(\$bArray[\$i][0], \$LenArrayItem - 3, 4)
;_MsgBox("\$IsItAsterixDotAsterix:   " & \$IsItAsterixDotAsterix)
\$bArray[\$i][2] = @ScriptLineNumber

If \$IsItAsterixDotAsterix = "\*.*" Then
;_MsgBox("\*.* " & @CRLF & @CRLF & \$IsItAsterixDotAsterix)
;_MsgBox("StringLen(\$bArray[\$i][0] " & @CRLF & @CRLF & StringLen(\$bArray[\$i][0]) & @CRLF & @CRLF & "StringLen(\$bArray[\$i][0] - 4 " & @CRLF & @CRLF & StringLen(\$bArray[\$i][0]) - 4)
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], StringLen(\$bArray[\$i][0]) - 4)
;_MsgBox("A * or \ existed " & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)

ElseIf StringTrimRight(\$IsItAsterixDotAsterix, 2) = "\*" Then
;_MsgBox("\* " & @CRLF & @CRLF & \$IsItAsterixDotAsterix)
;_MsgBox("StringLen(\$bArray[\$i][0] " & @CRLF & @CRLF & StringLen(\$bArray[\$i][0]) & @CRLF & @CRLF & "StringLen(\$bArray[\$i][0] - 4 " & @CRLF & @CRLF & StringLen(\$bArray[\$i][0]) - 2)
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], StringLen(\$bArray[\$i][0]) - 2)
;_MsgBox("A * or \ existed " & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)

Else
;_MsgBox("We shouldn't be able to see this so what's wrong?: " & @CRLF & @CRLF & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
EndIf
EndIf

Case \$IsThereAnAsterixOrSlash = "\"
;_MsgBox("A * or \ existed " & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], StringLen(\$bArray[\$i][0]) - 1)
;_ArrayDisplay(\$bArray, @ScriptLineNumber)

Case Else
;_MsgBox("We have a good full file path. " & @CRLF & @CRLF & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
\$bArray[\$i][1] = \$bArray[\$i][0]
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndSelect

Else
;===========================================================================================================================
;Check if no possible file extension by looking if returned regex length equals array element string length

;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$bArray[\$i][2] = @ScriptLineNumber
; Could be: C:\S\*

\$dArray = StringRegExp(\$bArray[\$i][0], "^(.+\\\w+)", 2)
If @error <> 0 Then
;_MsgBox("SECOND REGEX FAILED AND SET ERROR")
\$bArray[\$i][2] = @ScriptLineNumber
EndIf

#cs
Full String Match On:

C:\S
C:\S [return matches source, we have a winner and we already like this guy so we will do nothing to him]

#ce

\$LenRegEx = StringLen(\$dArray[0])
\$LenArrayItem = StringLen(\$bArray[\$i][0])

;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$bArray[\$i][2] = @ScriptLineNumber

If \$LenRegEx == \$LenArrayItem Then

;_MsgBox("DIR NO SLASH " & \$dArray[0])
\$bArray[\$i][2] = @ScriptLineNumber
\$bArray[\$i][1] = \$bArray[\$i][0]
;_ArrayDisplay(\$bArray, @ScriptLineNumber)

Else

\$eArray = StringRegExp(\$bArray[\$i][0], "^\w:\\[\. \( \) \w \\ \-]+\\[^\w \\ \.-]+", 2)
;\$eArray = StringRegExp(\$bArray[\$i][0], "(?x) ^ \w : \\ [\. \(\)\w\\-]+ \\ [^\w\\ \.-]+", 2) [Same results as above] Thank you for the insight JCHD
If @error <> 0 Then
;_MsgBox("THIRD REGEX FAILED AND SET ERROR")
\$bArray[\$i][2] = @ScriptLineNumber
\$eArray = StringRegExp(\$bArray[\$i][0], "^\w:\\[\. \( \) \w \\ \-]+\\[^\w \\ \.-]?", 2) ; C:\S\
If @error <> 0 Then
;_MsgBox("FOURTH REGEX FAILED AND SET ERROR")
\$bArray[\$i][2] = @ScriptLineNumber
\$eArray = StringRegExp(\$bArray[\$i][0], "^\w:\\[\. \(\)\w\\\-]+\\[^\w \\ -]+", 2) ; C:\S\*.* -FAILING BC LINE 136 "^(.+\\\w+)" HAS PARTIAL MATCH
If @error <> 0 Then
;_MsgBox("FIFTH REGEX FAILED AND SET ERROR")
\$bArray[\$i][2] = @ScriptLineNumber
Local \$LenRegEx = 0
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox("INSANE ->" & \$bArray[\$i][0] & "<-")
\$bArray[\$i][2] = @ScriptLineNumber
Else
Local \$LenRegEx = StringLen(\$eArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox(\$eArray[0] & @CRLF & @CRLF & \$LenRegEx)
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndIf
Else
Local \$LenRegEx = StringLen(\$eArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox(\$eArray[0] & @CRLF & @CRLF & \$LenRegEx)
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndIf
Else
Local \$LenRegEx = StringLen(\$eArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox(\$eArray[0] & @CRLF & @CRLF & \$LenRegEx)
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
If \$LenRegEx = \$LenArrayItem Then
\$bArray[\$i][1] = \$bArray[\$i][0]
\$bArray[\$i][2] = @ScriptLineNumber
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndIf
EndIf

\$fArray = StringRegExp(\$bArray[\$i][0], "^\w\:\\[\. \(\)\w\\\-]+\\[^\w \\ -]+", 2)
If @error <> 0 Then
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
Else
Local \$LenRegEx = StringLen(\$fArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox(\$fArray[0] & @CRLF & @CRLF & \$LenRegEx)
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
If \$LenRegEx = \$LenArrayItem Then
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], 4)
;\$bArray[\$i][1] = \$bArray[\$i][0]
\$bArray[\$i][2] = @ScriptLineNumber
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
\$LenRegEx = 0
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
Else
\$gArray = StringRegExp(\$bArray[\$i][0], "^\w\:\\[\. \(\)\w\\\-]+\\[^ \\ -]+", 2)
If @error <> 0 Then
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
Else
Local \$LenRegEx = StringLen(\$gArray[0])
Local \$LenArrayItem = StringLen(\$bArray[\$i][0])
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
If \$LenRegEx = \$LenArrayItem Then
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], 6)
;\$bArray[\$i][1] = \$bArray[\$i][0]
\$bArray[\$i][2] = @ScriptLineNumber
;_MsgBox("\$LenRegEx = " & @CRLF & @CRLF & \$LenRegEx & @CRLF & @CRLF & "\$LenArrayItem = " & @CRLF & @CRLF & \$LenArrayItem)
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndIf
EndIf
EndIf
EndIf

\$IsThereAnAsterixOrSlash = StringMid(\$bArray[\$i][0], \$LenArrayItem, 1)

;_MsgBox(\$bArray[\$i][0] & @CRLF & @CRLF & "->" & \$IsThereAnAsterixOrSlash & "<-")
\$bArray[\$i][2] = @ScriptLineNumber

Select
Case \$LenRegEx == \$LenArrayItem

#cs
Full String Match On:

C:\S\
C:\S\*
#ce
If \$IsThereAnAsterixOrSlash = "*" Then
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], 2)
;_MsgBox("An * existed " & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
EndIf

If \$IsThereAnAsterixOrSlash = "\" Then
\$bArray[\$i][1] = StringTrimRight(\$bArray[\$i][0], 1)
;_MsgBox("A \ existed " & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber
;_ArrayDisplay(\$bArray, @ScriptLineNumber)
Else
;_MsgBox("OUCH Who Knows")
\$bArray[\$i][2] = @ScriptLineNumber
EndIf

Case Else
;_MsgBox("We shouldn't be able to see this so what's wrong?: " & @CRLF & @CRLF & \$bArray[\$i][0])
\$bArray[\$i][2] = @ScriptLineNumber

EndSelect

EndIf
EndIf
;===========================================================================================================================
Next

\$bArray[0][0] = "*** Source Format of Text ***"
\$bArray[0][1] = "*** Reformatted Text ***"
\$bArray[0][2] = "*** Script Line Exited ***"

_ArrayDisplay(\$bArray, "Array @ End")

; #FUNCTION# ====================================================================================================================
; CUSTOM MSGBOX - ADDS SCRIPT LINE NUMBER AS TITLE FOR DEBUGGING - ADD MSGBOXES TO SOURCE IF NEEDED

; EXAMPLE MSGBOX
;_MsgBox("The value for \$stringinput is not as expected == " & \$stringinput)

Func _MsgBox(\$sText, \$sTitle = @ScriptLineNumber)
MsgBox(0, "-" & \$sTitle & "-", \$sText)
EndFunc   ;==>_MsgBox
; ===============================================================================================================================```

Edited by Casey

##### Share on other sites

Let's see:

```#include <Array.au3>

\$eArray = StringRegExp("C:\S\*", "(?x) ^ \w : \\ [\. \(\)\w\\-]+ \\ [^\w\\ \.-]+", 2)
_ArrayDisplay(\$eArray)```

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)

##### Share on other sites

JCHD,

Thank you and I am very sorry. Like I said I was getting cross eyed and the string that I'm stuck on is "C:\S\" and not "C:\S\*". My RegEx actually works on that one. The problem is that it also works on the other using tester. I'll also say that though it is going to take me a bit to read through your version, it looks a bit more intelligent and I think I'll be able to learn something from it. I spotted an error in trimming a string so I have updated my code above and I also see more problems down the line which is fine and why I am working through this exercise.

Casey

##### Share on other sites

This is the + quantifier right at the end of the pattern that prevents matching on "C:\S\" by requiring at least one char after the last backslash.

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)

##### Share on other sites

Oh, you on it! I had to add another bit of logic after it failed out on the third RegEx. Added a fourth replacing the + with a ? to catch "C:\S\". I'll update my code in a minute. Now just need to tweak the logic to get rows 8-10 and I'll be done. Thanks a million for catching that.

Casey

## 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

• ### Similar Content

• By MyEarth
Hello, i need to validate a string can be different things. I just need a True - False return value, no groups or things like that. It will be always one line at time to be processed by StringRegEx
Valid:
13:52|String
02:52 XX|String
13:52~SUN, MON, TUE, WED, THU, FRI, SAT|String
02:52 XX~SUN, MON, FRI|String
22/04/2017 13:52|String
22/04/2017 02:52 YY|String
Not Valid
22/04/2017 13:52~Dom|String
I need to validate until and inclusively the | after that i don't care
The XX and YY value are two \$sVariable from my script
SUN, MON, TUE, WED, THU, FRI, SAT are fixed value, the can be mixed but always in the same order like
SUN
SUN, TUE, WED
SUN, SAT
The time can be 12 or 24 hours, the date is always in the same format DD/MM/YYYY. If there is a date can't be a day after that ( see not valid )
Well i think is all
Sorry if i don't provide a working code, regex is too way complex.
Thanks
• By DavidLago
Hello.
I need to list only the folders that has a name composed of numbers only.
How do I do this?
OBS: I just posted the relevant content to the folder.
Global \$path = "G:\jobs\" For \$i = 1 To \$aArray[0] Local \$search = FileFindFirstFile(\$path & \$aArray[\$i] & "\[0-9]" ) I tried with "\*.*" and it returns me the expected result, but the other doesn't.
• By nikink
Hi all, it's been a while since I last used regular expressions and I find myself out of time to experiment with this particular issue, so I throw myself upon your mercy and expertise.
I am looking to create a function that will say whether or not a supplied string is a valid UUID or not.
Local \$sTestF = '4C4C4544-004A-4C10-8054-B7C04F46343' Local \$sTestT = '4C4C4544-004A-4C10-8054-B7C04F463432' ConsoleWrite('False = ' & _IsValidUUID(\$sTestF) & @CRLF) ConsoleWrite('True = ' & _IsValidUUID(\$sTestT) & @CRLF) Func _IsValidUUID(\$sUUID) ;[\p{XDigit}]{8}-[\p{XDigit}]{4}-[34][\p{XDigit}]{3}-[89ab][\p{XDigit}]{3}-[\p{XDigit}]{12} ; Test UUID = '4C4C4544-004A-4C10-8054-B7C04F463432' Local \$sRegExp = '([:xdigit:]){8}\-([:xdigit:]){4}\-([34])([:xdigit:]){3}\-([89ab])([:xdigit:]){3}\-([:xdigit:]){12}' ConsoleWrite(StringRegExp(\$sUUID, \$sRegExp) & @CRLF) Local \$Result = StringRegExp(\$sUUID, \$sRegExp) ConsoleWrite(\$Result & @CRLF) If @error Then ConsoleWrite('Error: [' & @error & ']' & @CRLF) Return 'False' Else ConsoleWrite('Error2: [' & @error & ']' & @CRLF) Return 'True' EndIf EndFunc In the line under the Function call, you'll see the regex I found to do this from a google search. That was my starting point, and I'm trying to get it to work in Au3 and failing miserably.
\$sTestF is a known invalid String
\$sTestT is a known valid String
Everything I've tried so far has produced the same results for both.
Any help you could provide me is greatly appreciated. Thanks for your time!
• By Trong
Hi,
I need help string RegEx to get string from CREATE to GO
#include <StringConstants.au3> ;~ Global \$fileSQL1 = @ScriptDir & "\fileSQL1.sql" ;~ Global \$fileSQL2 = @ScriptDir & "\fileSQL2.sql" Global \$tmpSQLfile = @TempDir & "\tmpFile.sql" OnAutoItExitRegister("_OnExit") _SetTMPsql() If Not FileExists(\$tmpSQLfile) Then OnAutoItExitUnRegister("_OnExit") Exit MsgBox(48, "/!\", "File: " & \$tmpSQLfile & @CRLF & " is not Exists!", 3) EndIf Global \$ContentSQLfile = FileRead(\$tmpSQLfile) _Start() Func _Start() Local \$aArray, \$iOffset = 1, \$stringRegExp = '(?i)CREATE(.*?)GO' While 1 \$aArray = StringRegExp(\$ContentSQLfile, \$stringRegExp, \$STR_REGEXPARRAYMATCH, \$iOffset) If @error Then MsgBox(48, "StringRegExp Error " & @error, "+> StringRegExp: " & \$stringRegExp & @CRLF & @CRLF & "=> With STRING:" & @CRLF & @CRLF & \$ContentSQLfile) ExitLoop EndIf \$iOffset = @extended For \$i = 0 To UBound(\$aArray) - 1 MsgBox(0, "RegExp Test with Option 1 - " & \$i, \$aArray[\$i]) Next WEnd EndFunc ;==>_Start Func _SetTMPsql() Local \$tmpSQLContent = "" \$tmpSQLContent &= "USE [Master]" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "CREATE DATABASE [Sales] ON PRIMARY " & @CRLF \$tmpSQLContent &= "( NAME = N’Sales’, FILENAME = N’\FSASQLDBSales.mdf’ , " & @CRLF \$tmpSQLContent &= " SIZE = 2GB , MAXSIZE = 8GB, FILEGROWTH = 1GB )" & @CRLF \$tmpSQLContent &= "LOG ON " & @CRLF \$tmpSQLContent &= "( NAME = N’Sales_log’, FILENAME = N’\FSASQLDBSales_log.ldf’ , " & @CRLF \$tmpSQLContent &= " SIZE = 1GB , MAXSIZE = 2GB , FILEGROWTH = 10%)" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "USE [Sales]" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "-- Table Product" & @CRLF \$tmpSQLContent &= "CREATE TABLE [dbo].[Product]" & @CRLF \$tmpSQLContent &= "(" & @CRLF \$tmpSQLContent &= " [ProductId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF \$tmpSQLContent &= " [ProductName] [nchar](50) NULL," & @CRLF \$tmpSQLContent &= " [ProductDescription] [nchar](3000) NULL," & @CRLF \$tmpSQLContent &= " [ProductPrice] MONEY NULL" & @CRLF \$tmpSQLContent &= ") ON [PRIMARY]" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "-- Table Sales" & @CRLF \$tmpSQLContent &= "CREATE TABLE [dbo].[Sales]" & @CRLF \$tmpSQLContent &= "( " & @CRLF \$tmpSQLContent &= " [SaleId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF \$tmpSQLContent &= " [SaleName] [nchar](50) NULL," & @CRLF \$tmpSQLContent &= " [SaleInfo] [nchar](3000) NULL," & @CRLF \$tmpSQLContent &= " [SaleMoney] MONEY NULL" & @CRLF \$tmpSQLContent &= ") ON [PRIMARY]" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "SET ANSI_NULLS ON" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "SET QUOTED_IDENTIFIER ON" & @CRLF \$tmpSQLContent &= "GO" & @CRLF \$tmpSQLContent &= "" & @CRLF \$tmpSQLContent &= "-- The End" & @CRLF Local \$hOpen = FileOpen(\$tmpSQLfile, 2 + 8 + 128) FileWrite(\$hOpen, \$tmpSQLContent) Return FileClose(\$hOpen) EndFunc ;==>_SetTMPsql Func _OnExit() Exit FileDelete(\$tmpSQLfile) EndFunc ;==>_OnExit
mikell

• By MuffinMan
I am trying to rebuild an old single signon script that has been giving us a bit of trouble lately.  I didn't write it and it was written in another script language.  If the target program is already open it will have the current user's last name as part of the window text, which I am trying to compare against the user name to see if I should just WinActivate or Process Close and start the program over.  I will be provided the username like "jones", or "smith" and the title check works fine for last names (with no spaces), but if the last name DOES contains spaces, say "Nom De Plume", then all I will be given as a username is "nomdeplume".  Is there any way (via a regex maybe) that I can still check the text on the screen and somehow ?  I have been reading about the Advanced (4) mode of WinTitleMatchMode, but it is over my head.  Any help is appreciated.  Here is a small reproducer script:
Opt("WinTitleMatchMode", -1) Run("Notepad") WinWait("[CLASS:Notepad]", "", 10) Send ("Smith" & @CRLF & "Jones" & @CRLF & "Nom De Plume" & @CRLF) If WinExists("[CLASS:Notepad]", "jones") Then MsgBox(0,"FOUND","Found Jones") EndIf If WinExists("[CLASS:Notepad]", "nomdeplume") Then MsgBox(0,"FOUND","Found Nom De Plume") EndIf