Jump to content

_Stringbetween issue causing muddy results


 Share

Recommended Posts

#include <String.au3>

$test = '<"100" tester="Things">Nowhere'
$result = _StringBetween($test, '"', '"')
For $a In $result
    ConsoleWrite($a & @CRLF)
Next

I would expect there to be a 2 entry array containing "100" and "Things". The issue is _StringBetween is not ignoring the end point and is instead using the end point character of " as the beginning of the next check in line.

Expected result:

100
Things

Actual result:

100
 tester=
Things 

Am I missing something or is this a bug? I would expect that once a "chunk" between something has been identified that it will then go from that point onwards and NOT muddy up the results by including a part of the previous check aka the " end character. Very confusing.

Link to comment
Share on other sites

In the _StringBetween function shouldn't there be a check so that if the beginning and the ending parts are identical that it will start searching for additional matches after the last ending part so as to not create unwanted results? Currently if the ending and starting points are the same, _StringBetween acts more like StringSplit, which is not what _Stringbetween is intended for.

Link to comment
Share on other sites

In most cases, using StringRegExp directly is a safer bet since you can tailor the pattern to match exactly the conditions your context imposes.

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

I am not very good with regex. But it appears after checking out the UDF for _StringBetween that it uses regex already, although none of it makes any sense to me at all. The function works great in every other case except when your beginning and ending are the same string.

Link to comment
Share on other sites

I tested your script on AutoIt 3.3.8.1 and I get correct result:

100

Things

Hmm so something is gotten screwy with the new version of autoit? Can anyone else replicate this? It might need escalating to developers.

Edited by Morthawt
Link to comment
Share on other sites

  • Moderators

Morthawt,

The RegEx used in the function has been changed to use a lookahead which means the second delimiter is not eaten as part of the pattern. A bug in my opinion as I would expect the behaviour as in 3.3.8.1 - please report it in Trac so that it can be discussed further. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I raised the issue >some time ago see #2460 and svn revision 9009 by jpm.

We regularly see examples with $end = $start where it is desirable to handle $end as the next $start, and another set of examples where it makes no sense. In all cases the reasonning behind a specific case is correct but gives incorrect results for the other semantic.

Is this a situation where we want an extra $flag parameter?

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

  • Moderators

jchd,

 

Is this a situation where we want an extra $flag parameter?

My first thought. ;)

Over to you! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I really would hope this is resolved at some point because it renders the function useless in situations where the beginning and end are the same, if there is no other string you can use that would make it unique from the other you are completely "up"useless"the creek"completely"with no"truly"paddle"needs fixing"in sight". Splitting that up with the current _StringBetween just will not render a coherent sentence even though logically it should because all the bold words you want are between " and ", all the rest is between the instances we want in dead space.

Link to comment
Share on other sites

Morthawt,

It is only useless in your precise situation. The change occured after several users complaining exactly for the other reason. There is no more logic or truth in any of the two versions. Hence I believe with Melba23 that an optional flag can make everyone happy.

In the meantime, I can only recommend that you use StringRegExp as an interim solution.

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

  • Moderators

Morthawt,

Just add a renamed copy of the old version of the function to your script and call that instead: :)

; #FUNCTION# ====================================================================================================================
; Name...........: _StringBetween (3.3.8.1 version)
; Description ...: Returns the string between the start search string and the end search string.
; Syntax.........: _StringBetween($s_String, $s_start, $s_end[, $v_Case = -1])
; Parameters ....: $s_String       - The string to search.
;                  $s_start        - The beginning of the string to find.  Passing a blank string starts at the beginning
;                  $s_end          - The end of the string to find.  Passing a blank string searches from $s_start to end
;                  $v_Case         - Optional: Case sensitive search. Default or -1 is not Case sensitive else Case sensitive.
; Return values .: Success - A 0 based $array[0] contains the first found string.
;                  Failure - 0
;                  |@Error  - 1 = No inbetween string found.
; Author ........: SmOke_N (Thanks to Valik for helping with the new StringRegExp (?s)(?i) isssue)
; Modified.......: SmOke_N - (Re-write for speed and accuracy)
; Remarks .......: 2009/05/03 Script breaking change, removed 5th parameter
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _StringBetween($s_String, $s_Start, $s_End, $v_Case = -1)

    ; Set case type
    Local $s_case = ""
    If $v_Case = Default Or $v_Case = -1 Then $s_case = "(?i)"

    ; Escape characters
    Local $s_pattern_escape = "(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)"
    $s_Start = StringRegExpReplace($s_Start, $s_pattern_escape, "\\$1")
    $s_End = StringRegExpReplace($s_End, $s_pattern_escape, "\\$1")

    ; If you want data from beginning then replace blank start with beginning of string
    If $s_Start = "" Then $s_Start = "\A"

    ; If you want data from a start to an end then replace blank with end of string
    If $s_End = "" Then $s_End = "\z"

    Local $a_ret = StringRegExp($s_String, "(?s)" & $s_case & $s_Start & "(.*?)" & $s_End, 3)

    If @error Then Return SetError(1, 0, 0)
    Return $a_ret
EndFunc   ;==>_StringBetween
Now, as you are making all the fuss about this - when are you going to create a bug in Trac? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Morthawt,

For...In should generally be used for Objects not Arrays as that's what For...To is designed for. I know people will argue with me on this, but I have explained my reasoning before, so just search the Forum.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

guinness,

Then why does AutoIt allow the use of (1D) arrays with a For...In loop?

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

guinness,

Then why does AutoIt allow the use of (1D) arrays with a For...In loop?

Using For...In with an Array is only useful if you're reading the contents of the Array.

From past experience people tend not to read the help file thoroughly, so by getting into the habit of using For...To, will stop posts on the lines of "AutoIt is broken, can't write to Array entry" as they're using For...In. Tell me, did you know that Arrays couldn't be written to in a For...In loop until I told?

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

guinness,

No, because I have a (good) habit of always using the For...To loop and not For...In (unless necessary).

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

  • Moderators

Hi,

Please test this new version which has an additional parameter to determine the mode used:

#include <Array.au3>

$sTest = '<"100" tester="Things">Nowhere'

$aRet = _StringBetween_New($sTest, '"', '"') ; Default mode 0 - ending delimiter is not part of next search
_ArrayDisplay($aRet, "New - 8 style", Default, 8)

$aRet = _StringBetween_New($sTest, '"', '"', Default, 1) ; Mode 1 - ending delimiter is part of next search 
_ArrayDisplay($aRet, "New - 10 Style", Default, 8)

Func _StringBetween_New($sString, $sStart, $sEnd, $fCase = False, $iMode = 0)
    ; Set correct case sensitivity
    If $fCase = Default Then
        $fCase = False
    EndIf
    Local $sCase = "(?is)"
    If $fCase Then
        $sCase = "(?s)"
    EndIf

    ; Set mode
    If $iMode <> 1 Then $iMode = 0

    ; If you want data from beginning then replace blank start with beginning of string
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

    ; If you want data from a start to an end then replace blank with end of string
    If $iMode Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf

    Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc
Comments welcomed. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

Please test this new version which has an additional parameter to determine the mode used:

#include <Array.au3>

$sTest = '<"100" tester="Things">Nowhere'

$aRet = _StringBetween_New($sTest, '"', '"') ; Default mode 0 - ending delimiter is not part of next search
_ArrayDisplay($aRet, "New - 8 style", Default, 8)

$aRet = _StringBetween_New($sTest, '"', '"', Default, 1) ; Mode 1 - ending delimiter is part of next search 
_ArrayDisplay($aRet, "New - 10 Style", Default, 8)

Func _StringBetween_New($sString, $sStart, $sEnd, $fCase = False, $iMode = 0)
    ; Set correct case sensitivity
    If $fCase = Default Then
        $fCase = False
    EndIf
    Local $sCase = "(?is)"
    If $fCase Then
        $sCase = "(?s)"
    EndIf

    ; Set mode
    If $iMode <> 1 Then $iMode = 0

    ; If you want data from beginning then replace blank start with beginning of string
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

    ; If you want data from a start to an end then replace blank with end of string
    If $iMode Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf

    Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc
Comments welcomed. :)

M23

 

Works flawlessly for me :) I sense good things from this.

Link to comment
Share on other sites

Hi M23,

This is nit-picking and not a likely scenario but I thought I would mention it.  Result strings containing an EOL will display as a concatenation in the array element.  Might be confusing/misleading to some users. 

Not advocating any actrion one way or the other, just wanted to mention it...

#include <Array.au3>

; mode 0 test

$aRet = _StringBetween_New('\first' & @crlf & 'second\third\', '\', '\')
if isarray($aRet) then
    ConsoleWrite('! _StringBetween Results mode = 0' & @LF)
    for $1 = 0 to ubound($aRet) - 1
        ConsoleWrite($aRet[$1] & @LF)
    Next
endif
_ArrayDisplay($aRet, "Mode 0 - start and end ", Default, 8)

; mode 1 test

$aRet = _StringBetween_New('\first' & @crlf & 'second\third\', '\', '\',default,1)
if isarray($aRet) then
    ConsoleWrite('! _StringBetween Results mode = 1' & @LF)
    for $1 = 0 to ubound($aRet) - 1
        ConsoleWrite($aRet[$1] & @LF)
    Next
endif
_ArrayDisplay($aRet, "Mode 1 - start and end ", Default, 8)


Func _StringBetween_New($sString, $sStart, $sEnd, $fCase = False, $iMode = 0)
    ; Set correct case sensitivity
    If $fCase = Default Then
        $fCase = False
    EndIf
    Local $sCase = "(?is)"
    If $fCase Then
        $sCase = "(?s)"
    EndIf

    ; Set mode
    If $iMode <> 1 Then $iMode = 0

    ; If you want data from beginning then replace blank start with beginning of string
    $sStart = $sStart ? "\Q" & $sStart & "\E" : "\A"

    ; If you want data from a start to an end then replace blank with end of string
    If $iMode Then
        $sEnd = $sEnd ? "(?=\Q" & $sEnd & "\E)" : "\z"
    Else
        $sEnd = $sEnd ? "\Q" & $sEnd & "\E" : "\z"
    EndIf

    Local $aReturn = StringRegExp($sString, $sCase & $sStart & "(.*?)" & $sEnd, 3)
    If @error Then Return SetError(1, 0, 0)
    Return $aReturn
EndFunc

Hmmm...Now where is that bird you are always trying to swat?!??

kylomas

edit: Yes, I know it's how _ArrayDisplay works

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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