kylomas Posted November 20, 2012 Share Posted November 20, 2012 Regexp Experts, I found this regexp pattern from a snippet posted by either Malkey of AZJIO (sorry, don't remember which). After reading the PCRE doc linked to in the help file, AGAIN, I do not understand the use of the circumflex. local $str1 = fileread($fl_name1) $str1 = stringregexpreplace($str1,'(?m:^)rn',"") Could someone break this pattern down (preferrably in the format that M23 and jchd use). My understanding of the pattern at his point is: ( start group ?m: set group to non-capturing, multiline ^ Anchor line/string at start? (how does it know what start is?) ) close group rn match on @cr @lf as first two chars after anchor Thanks, 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 More sharing options...
guinness Posted November 20, 2012 Share Posted November 20, 2012 This SRE probably makes more sense to you >> #cs (?m) ^ and $ match newlines within data. ^ Start matching at the beginning of a new line. rn Match @CRLF at the start of a line. #ce Local $sData = '' For $i = 1 To 100 If Random(0, 1, 1) Then $sData &= @CRLF Else $sData &= 'Random' & @CRLF EndIf Next ConsoleWrite(StringRegExpReplace($sData, '(?m)^rn', '')) ; Only works with CRLF line endings & not @CR or @LF.You seemed to have grasped the basic understanding. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
guinness Posted November 20, 2012 Share Posted November 20, 2012 (edited) What about this instead? #cs (?m) ^ and $ match newlines within data. ^ Start matching at the beginning of a new line. rn Match @CRLF or @LF or @CR or blank space with a line ending at the start of a line. #ce Local $sData = '' For $i = 1 To 10 If Random(0, 1, 1) Then If Random(0, 1, 1) Then $sData &= ' ' & @CRLF Else $sData &= @CR EndIf Else $sData &= 'Random' & @CRLF EndIf Next ConsoleWrite('Before: ' & @CRLF & $sData & @CRLF) ConsoleWrite('After: ' & @CRLF & StringRegExpReplace($sData, '(?m)^[ rn]*', '')) OR by the SRE master >> ConsoleWrite(_RemoveBlankLines(FileRead(@ScriptFullPath))) Func _RemoveBlankLines($sString) ; By Robjong. Return StringRegExpReplace($sString, '(?m:^s*r?n)|s*z', '') EndFunc ;==>_RemoveBlankLines Edited November 20, 2012 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted November 20, 2012 Author Share Posted November 20, 2012 guinness, Thanks for the prompt reply. I'm starting to get it (with much thanks to Rob!!). I keep tripping up on stupid shit, like, now I'm wondering exactly what does the PCRE doc mean by the phrase "new line or string". Gotta keep this short...am using a keyboard that is a little like timing a race with a sun-dial! 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 More sharing options...
AZJIO Posted November 20, 2012 Share Posted November 20, 2012 $sInput = 'Removes' & @LF & @CRLF & @LF & 'empty lines' $sOutput = StringRegExpReplace($sInput, '(rn|r|n){2,}', '1') MsgBox(0, "Yes?", $sInput & @LF & '--------------' & @LF & $sOutput) My other projects or all Link to comment Share on other sites More sharing options...
AZJIO Posted November 20, 2012 Share Posted November 20, 2012 guinness My other projects or all Link to comment Share on other sites More sharing options...
guinness Posted November 20, 2012 Share Posted November 20, 2012 guinnessOK, I will re-think about adding it. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted November 20, 2012 Author Share Posted November 20, 2012 AZJIO, Why does this not remove all EOL chars resulting in one long string? '(rn|r|n){2,}' 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 More sharing options...
AZJIO Posted November 21, 2012 Share Posted November 21, 2012 kylomas, {2,} - removes two or more repetitions. Can not delete one instance. My other projects or all Link to comment Share on other sites More sharing options...
kylomas Posted November 21, 2012 Author Share Posted November 21, 2012 (edited) AZJIO, When I run this #include <array.au3> local $str1 = @crlf & '1' & @crlf & '2' & @crlf & '3' & @crlf & '4' & @crlf & '5' & @crlf & @crlf local $str2 = stringregexpreplace($str1,'(rn|r|n){2,}',"") consolewrite($str1 & $str2 & @lf) I get one continuous string...am I doing something wrong? kylomas edit: when I change the repetitions to 3 it seems to work...can you explain why? Edited November 21, 2012 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 More sharing options...
dany Posted November 21, 2012 Share Posted November 21, 2012 (edited) @CRLF equals rn match rn against your group, first entry rn; a hit! Next character ?, does the group repeat? No, doesn't match regex pattern. Back to start of string. match rn against your group, second entry r; a hit! Next character n, does the group repeat? match n against your group, third entry; a hit! Two hits satisfies the quantifier {2,} ... Next character ?, does the group repeat? No, doesn't satisfy the quantifier {3,} Edited November 21, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
Bowmore Posted November 21, 2012 Share Posted November 21, 2012 (edited) @kylomas Yes you missed the replacement. This method as shown by AZJIO in post #5 replaces multiple instances of the line ending with a single line ending. #include <array.au3> local $str1 = @crlf & '1' & @crlf & '2' & @crlf & '3' & @crlf & '4' & @crlf & '5' & @crlf & @crlf local $str2 = stringregexpreplace($str1,'(rn|r|n){2,}',"1") consolewrite($str1 & $str2 & @lf) Edited November 21, 2012 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
kylomas Posted November 21, 2012 Author Share Posted November 21, 2012 @Bowmore, Duh!! Thanks 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 More sharing options...
guinness Posted November 21, 2012 Share Posted November 21, 2012 Well this was an interesting discussion that caught the attention of many. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted November 21, 2012 Author Share Posted November 21, 2012 @all - thank you for you patience and Happy Thanksgiving to our U.S. contingent. (automatically signed off due to stupid quota exceeded) 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 More sharing options...
guinness Posted November 21, 2012 Share Posted November 21, 2012 @all - thank you for you patience and Happy Thanksgiving to our U.S. contingent.(automatically signed off due to stupid quota exceeded)Quota exceeded? Not from the Forum I hope. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Robjong Posted November 22, 2012 Share Posted November 22, 2012 (edited) Hi,I'm late to the party I see, but here is some additional information.The circumflex/caret has 3 functions in a regular expression, depending on the mode and position in the pattern.(1) By default it matches the beginning of the subject, same as \A. ($ will match the end of subject, same as \z)(2) If multiline mode is enabled, by setting the m flag, it matches the beginning of the subject and the start of a new line ($ will match the end of subject and end of line).(3) If it is used in a character class it only has a special meaning if it is the first character in the class. It will then negate the class, i.e. the class will match any character not in it.If you want to match a literal circumflex in a pattern it must be escaped (with a backslash, \^), in a character class it only needs to be escaped if it is the first character because it has no special meaning at any other position.It is also a zero-width expression, meaning it will match the position of a character (start of subject or newline) but not the character itsef, i.e. it will not include/return the character(s) in the match.; normal mode, beginning of subject anchor #cs - Match a string of only word characters (word characters are A-Z, a-z, 0-9 and _ (underscore). Equivalent to class [A-Za-z0-9_]) ^ the start of the subject \w+ one or more word characters $ the end of the subject #ce If StringRegExp("ABCD", '^\w+$') Then ConsoleWrite("The string consists only of ""word"" characters." & @LF) Else ConsoleWrite("The string does NOT consist of only ""word"" characters." & @LF) EndIf ; multiline mode, beginning of subject or newline #cs - Match full line comments (?m) m flag, enables multiline mode ^ the beginning of the subject or the beginning of a newline \h*; 0 or more horizontal whitespaces followed by a semicolon (?: open non-capturing group [[:punct:]]\h* non-alphanumeric priniting character followed by 0 or more horizontal whitespaces )? close non-capturing group, match group 0 or 1 times (? makes the group optional) ( open capturing group [^\r\n]* match any character except for \r (CR) or \n (LF) 0 or more times (^ negates the class) ) close capturing group #ce $aMatches = StringRegExp(FileRead(@ScriptFullPath), '(?m)^\h*;(?:[[:punct:]]\h*)?([^\r\n]*)', 3) For $i = 0 To UBound($aMatches) - 1 Step 1 ConsoleWrite("COMMENT: " & $aMatches[$i] & @LF) NextTo answer your question more directly...The beginning of a subject/string is always at position 0 (before the first character).The beginning of a line is either the beginning of the subject or directly after a newline (CRLF/CR/LF).Example:expandcollapse popup#include <Array.au3> ; subject $sString = "This is an example subject." & @LF & "Made up of two lines." ; ^ singleline mode, match the first 4 characters of the subject #cs ^ start of the subject .... followed by 4 characters #ce $aMatches = StringRegExp($sString, "^....", 3) _ArrayDisplay($aMatches, "Singleline") ; ^ multiline mode, match the first 4 characters of a line #cs (?m) m flag, enables multiline mode ^ start of the subject or line .... followed by 4 characters #ce $aMatches = StringRegExp($sString, "(?m)^....", 3) _ArrayDisplay($aMatches, "Multiline") ; singleline mode reproducer, match the first 4 characters of a subject #cs (....) capture 4 characters that are not newline characters [\s\S]* match any character (space and non-space) 0 or more times #ce $aMatches = StringRegExp($sString, "(....)[\s\S]*", 3) _ArrayDisplay($aMatches, "Singleline Reproducer") ; multiline mode reproducer, match the first 4 characters of a line #cs (?: open non-capturing group \A|\r\n|\r|\n match the start of the subject or newline characters ) close non-capturing group (....) capture 4 characters that are not newline characters #ce $aMatches = StringRegExp($sString, "(?:\A|\r\n|\r|\n)(....)", 3) _ArrayDisplay($aMatches, "Multiline Reproducer") ; advanced multiline mode reproducer, match the first 4 characters of a line #cs (?<= open positive lookbehind \A|\r\n|\r|\n match the start of the subject or newline characters ) close positive lookbehind .... match (and capture as global match) 4 characters that are not newline characters #ce $aMatches = StringRegExp($sString, "(?<=\A|\r\n|\r|\n)....", 3) _ArrayDisplay($aMatches, "Advanced Multiline Reproducer")Edit: Fixed spacing of commentsEdit2: added "word" character descriptionEdit3: added more direct answer Edited November 22, 2012 by Robjong Beege 1 Link to comment Share on other sites More sharing options...
kylomas Posted November 22, 2012 Author Share Posted November 22, 2012 Robjong, Thanks, this To answer your question more directly...The beginning of a subject/string is always at position 0 (before the first character).The beginning of a line is either the beginning of the subject or directly after a newline (CRLF/CR/LF). adds more clarity. I may get good at this yet, at least it is no longer voodoo, just Klingon.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 More sharing options...
jchd Posted November 24, 2012 Share Posted November 24, 2012 (edited) Let me resurect this --even later than late-- for a while as there is something incorrect here. In the example given: local $str1 = @crlf & '1' & @crlf & '2' & @crlf & '3' & @crlf & '4' & @crlf & '5' & @crlf & @crlf local $str2 = stringregexpreplace($str1,'(\r\n|\r|\n){2,}',"\1") consolewrite($str1 & $str2 & @lf) The issue I see is that the very first empty line is not removed (there is only one CRLF by its own). Instead, this works to remove all empty lines: local $str1 = @crlf & '1' & @crlf & '2' & @crlf & '3' & @crlf & '4' & @crlf & '5' & @crlf & @crlf local $str2 = StringRegExpReplace($str1,'(*BSR_ANYCRLF)(^\R|\R(?=\R))',"") consolewrite($str1 & @LF & '--------------' & @LF & $str2 & '------------' & @lf) Here I've chosen to leave the last line '5' with its @CRLF (which is technically wrong!). If this is not what's wanted, then one can use: local $str1 = @crlf & '1' & @crlf & @crlf & '2' & @crlf & @CRLF & @crlf & '3' & @crlf & '4' & @crlf & '5' & @crlf & @crlf local $str2 = StringRegExpReplace($str1,'(*BSR_ANYCRLF)(^\R|\R(?=\R)|\R\z)', "") ConsoleWrite($str1 & '--------------' & @LF & $str2 & '--------------' & @lf) As a sidenote it's well remembering that ^ and $ (as well as \A \a, \Z \z) are all assertions that "match" at specific positions. These sequences can never be used to capture anything. \R is different from this point of view in that it actually matches newlines sequences (depending on *BSR_xxx option) and that you can capture \R as the example shows. Final note: by default, \R matches any Unicode newline character or char sequence. Edited November 24, 2012 by jchd 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...
DXRW4E Posted November 24, 2012 Share Posted November 24, 2012 (edited) Hi all, another quick way $iFlag = 2 or $iFlag = 4or$str = "ect ect ect" $str = StringTrimLeft(StringRegExpReplace(@LF & StringRegExpReplace($str, 'r(?!n)', @CRLF), 'ns*(?=n)', ""), 1)about speed RegExp does not like too much "|" (Or. The expression on one side or the other can be matched.)(rn|r|n) ;or (*BSR_ANYCRLF)(^R|R(?=R)|Rz) ;ect ect ect ;ect ect ectI mean takes a reference point for strength (always takes a reference point to go fast), precisely the; n Not (rn|n|r) ect ect $str = StringRegExpReplace(@LF & StringRegExpReplace($str, 'r(?!n)', @CRLF), 'n(r?n)+', "") or $str = StringRegExpReplace(@LF & StringRegExpReplace($str, 'r(?!n)', @CRLF), 'ns*(?=n)', "")almost x3 times faster than thelocal $str2 = StringRegExpReplace($str1,'(*BSR_ANYCRLF)(^R|R(?=R))',"") ;or local $str2 = stringregexpreplace($str1,'(rn|r|n){2,}',"1") ;ect ect ect ;ect ect ectCiao. Edited November 24, 2012 by DXRW4E 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