gcue Posted May 1, 2014 Share Posted May 1, 2014 is there a difference in pattern syntax between stringregexp and regexp in say VBA? reason why i am asking is because i have a pattern that works in autoit but doesnt seem to work in VBA. i know this isnt a vba help forum but im working between autoit and vba and wanted to see if the patterns are compatible Private Function FixLink(s As String) 'BEGIN : create and set regular expression Dim regEx As Object Set regEx = CreateObject("vbscript.regexp") With regEx .IgnoreCase = True .MultiLine = False .Pattern = "^(?:.*?\K[^\\]+){3}" .Global = True End With FixLink = regEx.Replace(s, UCase(Environ("USERNAME"))) MsgBox (s & Chr(10) & FixLink) End Function Link to comment Share on other sites More sharing options...
guinness Posted May 1, 2014 Share Posted May 1, 2014 Did you try my regular expression? 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...
gcue Posted May 1, 2014 Author Share Posted May 1, 2014 yea it would crash vb - i simply replaced the pattern with this one and it didnt crash but it also didnt work so yea since both arent working.. thats why im wondering what the differences in pattern syntax are Link to comment Share on other sites More sharing options...
guinness Posted May 1, 2014 Share Posted May 1, 2014 I tested my regular expression in C# and it worked fine. 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...
mikell Posted May 1, 2014 Share Posted May 1, 2014 K is not supported in C# (neither probably in vba) Better use this $sNewPath = StringRegExpReplace($sFilePath, '(([^\\]+\\){2})[^\\]+' , '$1' & $sUserName) though StringSplit remains the simplest way $sNewPath = StringReplace($sFilePath, StringSplit($sFilePath, "\")[3], $sUserName) Link to comment Share on other sites More sharing options...
gcue Posted May 1, 2014 Author Share Posted May 1, 2014 (edited) interesting.. so there are pattern differences - sounds like they're minor tho? mikell that works and replaces where it should BUT it also replaces in more places where it shouldn't so like in the example here: Local $sUserName = "xavier" Local $sFilePath = "c:usersqwertytestdeezmorestuffin the end.xls" it becomes something like this c:usersxaviertestdeezxavierstuffxavier Edited May 1, 2014 by gcue Link to comment Share on other sites More sharing options...
mikell Posted May 1, 2014 Share Posted May 1, 2014 Sorry, I forgot the anchor StringRegExpReplace($sFilePath, '^(([^\\]+\\){2})[^\\]+' , '$1' & $sUserName ) Link to comment Share on other sites More sharing options...
gcue Posted May 2, 2014 Author Share Posted May 2, 2014 gorgeous! i even cried a little so how did you know what was compatible with what language.. is there documentation you have somewhere? thank you VERY much!!! Link to comment Share on other sites More sharing options...
gcue Posted May 2, 2014 Author Share Posted May 2, 2014 again works great... except i noticed that it will replace C:program filesquerty... also can i specify it for just C:usersqwerty... thanks again! Link to comment Share on other sites More sharing options...
jchd Posted May 2, 2014 Share Posted May 2, 2014 gcue, Every regular expression engine has its own set of metacharacters, anchors, conditions, etc. While there is many basic conventions in common between engines, there are a number of important or more subtle differences. You have to refer to the reference documentation for the engine you use. AutoIt uses the PCRE library as discussed at some length in our help file, but more advanced features and many details are to be found in the PCRE reference documentation. We're lucky: PCRE is among the top most comprehensive libraries available and certainly the most prevalent. 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...
gcue Posted May 2, 2014 Author Share Posted May 2, 2014 i tried both of these but neither worked. so i can only replace when the path is c:users.... "^(([^\\users]+\\){2})[^\\]+" "^(([^\\]+users\\){2})[^\\]+" "^(([^\\]+\\users){2})[^\\]+" Link to comment Share on other sites More sharing options...
mikell Posted May 2, 2014 Share Posted May 2, 2014 (edited) The pattern I posted is non-specific, so it will work on the 3rd element of any path If you need to be very specific i.e. with a path starting with 'c:users' only, then you must use a specific pattern too So is the one guinness posted before, or this simple one StringRegExpReplace($sFilePath, '^(c:\\users\\)[^\\]+' , '$1' & $sUserName) Edited May 2, 2014 by mikell Link to comment Share on other sites More sharing options...
Jury Posted May 4, 2014 Share Posted May 4, 2014 (edited) on this page: http://www.regular-expressions.info/tutorial.html under the heading: Different Regular Expression Engines you'll find some information for various engines and each tutorial gives information also i.e.: http://www.regular-expressions.info/unicode.html Edited May 4, 2014 by Jury Link to comment Share on other sites More sharing options...
gcue Posted May 5, 2014 Author Share Posted May 5, 2014 The pattern I posted is non-specific, so it will work on the 3rd element of any path If you need to be very specific i.e. with a path starting with 'c:users' only, then you must use a specific pattern too So is the one guinness posted before, or this simple one StringRegExpReplace($sFilePath, '^(c:\\users\\)[^\\]+' , '$1' & $sUserName) works great!!!! many thanks - again! Link to comment Share on other sites More sharing options...
gcue Posted May 5, 2014 Author Share Posted May 5, 2014 on this page: http://www.regular-expressions.info/tutorial.html under the heading: Different Regular Expression Engines you'll find some information for various engines and each tutorial gives information also i.e.: http://www.regular-expressions.info/unicode.html thanks for the references =) 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