Sign in to follow this  
Followers 0
guinness

StringRegExp and enumerating data inbetween a particular function.

25 posts in this topic

Below is a working example of what I'm trying to achieve.

As you can see it will find all the strings in between the function labelled _LanguageString(), but where this fails is when there is a closing bracket ")" inside the function itself, due to this being interpreted as the function's closing bracket. So my question is how can I improve the SRE to disregard the bracket in the function's string? Any advice would be greatly appreciated.

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString("MENU_HELP", "Help file")' & @CRLF & _
    "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    "

    ; Find data in between _LanguageString( and ). The function _LanguageString is included in a separate AutoIt.
    Local $aReturn = StringRegExp($sData, '(?s)(?i)_LanguageString\((.*?)\)', 3)
    If Not @error Then
    _ArrayDisplay($aReturn) ; Display the strings returned.
    EndIf
EndFunc   ;==>Example

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites



Hi,

this might not be the best solution but I think it will fit your needs

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString($MENU_HELP, "Help file")' & @CRLF & _
    "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    "
    ; Find data in between _LanguageString( and ). The function _LanguageString is included in a separate AutoIt.
    Local $aReturn = StringRegExp($sData, '(?s)(?i)_LanguageString\s*\(\s*((?:[''"].*?[''"]|\$\w+),\s*(?:[''"].*?[''"]|\$\w+))\)', 3) ; will allow the params to be literal strings and variables.
;~   Local $aReturn = StringRegExp($sData, '(?s)(?i)_LanguageString\s*\(\s*((?:[''"].*?[''"]|\$\w+)(?:,\s*(?:[''"].*?[''"]|\$\w+))?)\)', 3) ; if the second param of _LanguageString is optional use this one.
    _ArrayDisplay($aReturn) ; Display the strings returned.
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks Robjong, it's perfect! :)

Edit: In the initial example I wrote $MENU_HELP when it should've been "MENU_HELP" so this is what led me to believe it was wrong, but it was fault for writing the example incorrect. Cheers Robjong.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wow! Very nice indeed Robjong. I couldnt get around the single/double quotes

Edited by Beege

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Got mine to work. Only after looking at seeing how Robjong handled the quotes. :)

#include <Array.au3>
Example()
Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE", "An example string"))' & @CRLF & @CRLF & _
     'Local $sVar = _LanguageString("MENU_HELP", "Help file")' & @CRLF & _
     "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)"
    ; Find data in between _LanguageString( and ). The function _LanguageString is included in a separate AutoIt.
    Local $aReturn = StringRegExp($sData, '(?s)(?i)_LanguageString((.*?["|'']))', 3)
    If Not @error Then
    _ArrayDisplay($aReturn) ; Display the strings returned.
    EndIf
EndFunc   ;==>Example
Edited by Beege

Share this post


Link to post
Share on other sites

Beege, that's amazing too :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Thanks :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Nice one Beege.

However there is a small error in your pattern, the | int the character set should not be there, it is only used as a conditional in capturing groups, it would now also match |) as an ending.

The pattern could be something like this:

'(?is)_LanguageString((.*?["'']))'

Edit: added everything below...

The pattern Beege provided (the one above here) is nice and short but it has a small drawback compared to the pattern I posted, you should consider this when writing the final pattern.

If the string happens to include a quote followed by a closing parentheses it will 'break' the match, the pattern I provided only has this for the second param of _LanguageString,

if you will never encounter a quote followed by a closing parentheses in the first parameter of _LanguageString you should use Beege's pattern.

Also, I wrote mine that way because I suspected guinness would wan't to have both params separately at some point.

Example:

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE with a single quote (''foo'')", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString($MENU_HELP, "Help file")' & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (Having a quote followed by a closing parentheses in this string will break the match'') so you won''t see this part'), 0, 5, 100, 20) "
    ; Find data in between _LanguageString( and ). The function _LanguageString is included in a separate AutoIt.
;~   Local $aReturn = StringRegExp($sData, '(?is)_LanguageStrings*(s*((?:[''"].*?[''"]|$w+)s*,s*(?:[''"].*?[''"]|$w+)s*))', 3) ; last match is broken
    Local $aReturn = StringRegExp($sData, '(?is)_LanguageString((.*?["'']))', 3); first match is broken
    _ArrayDisplay($aReturn) ; Display the strings returned.
EndFunc   ;==>Example
Edited by Robjong

Share this post


Link to post
Share on other sites

Ahh yes your right. I was thinking or operator, but thats missing the whole point of the brackets. :)

Share this post


Link to post
Share on other sites

Gotcha! Of the top of my head I don't believe I have quotes inside brackets, but I'll do some more testing later on today.

Also, I wrote mine that way because I suspected guinness would wan't to have both params separately at some point.

As of now both are mandatory but this could change in the future.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi again,

I tried some more patterns and this is what i came up with.

It matches the first closing parentheses with an unescaped quote with the help of nagative lookbehind. this avoids most broken matches due to ') or ") in the strings and unescaped the quotes would cause a syntax error and are therefor unlikely to appear that way.

The pattern is a bit long but this is make sure signel and double quotes don't get mixed up, it allows literal string, variables and a single combination of the two.

I think this will work in most cases but it has not been thoroughly tested yet, so that's up to you if you like.

Pattern:

'(?is)_LanguageStrings*(s*((?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")")?s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")")?)s*)'

Example:

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE with a single quote (""foo"")", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString($MENU_HELP, "Help file")' & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString($foo & 'MENU_LICENSE', 'Please see readme (""License.txt"")'), 0, 5, 100, 20) " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (Having a quote followed by a brace closing parentheses in this string will break the match'') so you won''t see this part, or you will now'), 0, 5, 100, 20)  " & @CRLF
    Local $aReturn = StringRegExp($sData, '(?is)_LanguageStrings*(s*((?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")")?s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")")?)s*)', 3)
    If Not @error Then  _ArrayDisplay($aReturn) ; Display the strings returned.
EndFunc   ;==>Example

Edit: corrected pattern, moved the last questionmark in the pattern 1 pos to the left.

Edited by Robjong

Share this post


Link to post
Share on other sites

This appears to be a lot better than your initial post from the tests I've conducted. Though one last thing if for example I have the following '_LanguageString("TIP_1", "It appears you don't have administrator privileges.", 0)' and I simply duplicate this part ,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"))?s* it fails, but this is no biggy!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Robjong, Did you like contribute in the creation of regexp or something? cause that shit is crazy! :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Hey guinness,

try this one, it allows for the params to be digits (just digits, no floats or anything and not in combination with strings or vars) and has an optional 3rd param.

'(?is)_LanguageStrings*(s*((?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?(?:s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?)?)s*)'

I also made a minor correction to the last pattern I posted.

Edit: If you have any more requirements just tell me now so we can get it all in there ;), do you need access to the separate params for example?

Another edit: @Beege I wish :)

Yet another edit: Fixed syntax error in the pattern

Edited by Robjong

Share this post


Link to post
Share on other sites

Hey guinness, try this one, it allows for the params to be digits (just digits, no floats or anything and not in combination with strings or vars) and has an optional 3rd param.

Hey, you're quick for me Robjong. I tried it and there was an error with the syntax so I added an additional ' where the error occurred without any luck. Sorry about that. You've both helped me more than I could imagine.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

...error in the syntax? checking...

Edit: I updated my previous post with the fixed pattern and here is a working example...

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE with a single quote (""foo"")", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString( $MENU_HELP ,"Help file", 1 )' & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString($foo & 'MENU_LICENSE', 'Please see readme (""License.txt"")'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (Having a quote followed by a brace closing parentheses in this string will break the match'') so you won''t see this part, or you will now'), 0, 5, 100, 20)    " & @CRLF
;~     Local $aReturn = StringRegExp($sData, '(?isx)_LanguageStrings*(s*( (?:$w+(?:s*&)?s*)? (?: ''.*?(?<![^'']'')'' | ".*?(?<![^"]")" | d)?  s*,s*  (?:$w+(?:s*&)?s*)?  (?: ''.*?(?<![^'']'')'' | ".*?(?<![^"]")" | d )? (?: s*,s*  (?:$w+(?:s*&)?s*)?  (?: ''.*?(?<![^'']'')'' | ".*?(?<![^"]")" | d )?  )?  ) s*)', 3)
    Local $aReturn = StringRegExp($sData, '(?is)_LanguageStrings*(s*((?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?(?:s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?)?)s*)', 3)
    If Not @error Then _ArrayDisplay($aReturn) ; Display the strings returned.
EndFunc   ;==>Example
Edited by Robjong

Share this post


Link to post
Share on other sites

That's it! Thanks ever so much for your help and putting up with my constant changing the goal posts, you've managed to 'hit the nail on the head' with the last example. Lets hope someone else can benefit from this SRE in the future.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

I'm glad I was able to help. The principle is quite simple but the pattern a little less.

If anyone needs this I suggest checking out the pattern that is commented out in my previous post as it's a little bit easier to read.

Share this post


Link to post
Share on other sites

Just a hint for everyone having to deal/build non trivial patterns: make yourself the favor of using the PCRE_EXTENDED option (?x). That will allow you to freely use whitespaces to give your pattern superior readability. It of course need that when you need significant whitespace, you escape them.

I'll have my own look at the OP problem later.


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 this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Yes jchd that's well put, and don't forget you can also use # (Cross hatch) to comment lines in the patter, they are trailing comments and behave like the semi colon in AutoIt, this also means you have to escape any # characters you need in your pattern with a (backslash) like this # or it will cause an invalid pattern error.

Also here's is another version of the pattern which is a little shorter and requires atleast 1 parameter but also allows for as many as you like.

#include <Array.au3>

Example()

Func Example()
    ; An example of an AutoIt file.
    Local $sData = 'MsgBox(4096, "", _LanguageString("MENU_EXAMPLE with a single quote (""foo"")", "An example string"))' & @CRLF & @CRLF & 'Local $sVar = _LanguageString( $MENU_HELP ,"Help file", 1 )' & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString($foo & 'MENU_LICENSE', 'Please see readme (""License.txt"")'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (License.txt)'), 0, 5, 100, 20)    " & @CRLF & _
            "Local $iControl = GUICtrlCreateLabel(_LanguageString('MENU_LICENSE', 'Please see readme (Having a quote followed by a brace closing parentheses in this string will break the match'') so you won''t see this part, or you will now'), 0, 5, 100, 20)    " & @CRLF
;~     Local $aReturn = StringRegExp($sData, '(?isx)_LanguageStrings*(s*( (?:$w+(?:s*&)?s*)? (?: ''.*?(?<![^'']'')'' | ".*?(?<![^"]")" | d)?  (?: s*,s*  (?:$w+(?:s*&)?s*)?  (?: ''.*?(?<![^'']'')'' | ".*?(?<![^"]")" | d )?  )*  ) s*)', 3)
    Local $aReturn = StringRegExp($sData, '(?isx)_LanguageStrings*(s*((?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?(?:s*,s*(?:$w+(?:s*&)?s*)?(?:''.*?(?<![^'']'')''|".*?(?<![^"]")"|d)?)*)s*)', 3)
    If Not @error Then _ArrayDisplay($aReturn) ; Display the strings returned.
EndFunc   ;==>Example

Edit: It still has some problems with empty strings ""

Edit: grammer and explenation of comments

Edited by Robjong

Share this post


Link to post
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
Sign in to follow this  
Followers 0