Followers 0

# Regex - Drive letter - ellipses - two last folders from path

## 11 posts in this topic

Hallo Members,

I'm looking for a good regex to get the drive letter and the last two folders from a file path,

If the path is to long for the label width then show drive +   ellipses and two last folders.

ConsoleWrite($short) Tried to understand the regex, thats why I wrote "you saved my day" K.* was something new for me http://www.regular-expressions.info/keep.html #### Share this post ##### Link to post ##### Share on other sites Oh you are learning ! Sorry, here are the comments : '^\w:\\\K.*(?=\$^\$+\$^\$+\\?$)'

^        : beginning of string
\w:\\    : a word char + colon + antislash
\K       : escape sequence meaning 'forget what you've seen before'
.*       : the part to replace
\$^\$+  : antislash + one or more non-antislash char. Used twice
: end of string #### Share this post ##### Link to post ##### Share on other sites mikell, good explanation, as I wrote earlier \K is something new for me. With this fantastic forum and for example SRETester I learn every time something new. Next thing is improve my skills with AutoIt/Microsoft.XML DOM like jdelaney wrote #### Share this post ##### Link to post ##### Share on other sites #### 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 Followers 0 • ### Similar Content • By thoms Hello Forum, I'm trying to vertically center text in label controls, but no way. The search on the forum returns no result, or I don't search the right way When I insert a button and a label of same size close to each other, the text is centered on the button, but top aligned on the label, or edit. Which doesn't look really aesthetic Any idea is welcome Thanks in advance, Thoms • By TheAutomator Can anyone tell me why this isn't working?.. #include <array.au3>regexp = StringRegExp("test 'a b c'", "'([^']|'')*'|\S+", 3) _ArrayDisplay($regexp) trying to split this "test 'a b c' 'some other '' test'' ...'" into: 0: test 1: 'a b c' 2: ... but it gives me: 0: test 1: c • By anthonyjr2 Hi guys, I am pretty bad with regex, and am having some trouble trying to come up with an expression for a certain type of string. Basically I want to be able to tell if a string is of the format: AA#####A Where the A's are any letter from A-Z and the #'s are any digit from 0-9. I've been playing around with a regex tester online for a while but I can't really seem to grasp the concept very well. Could anyone give me any tips? This isn't exactly an AutoIt specific question which is why I didn't post it in General Help & Support. • By ViciousXUSMC So I ran into this crazy "program" that cant be uninstalled via WMI, MSIExec, etc. The only way to uninstall it was from Add/Remove programs manually... Or I found if you find it in the registry under HKCU and run the uninstall string, it will also uninstall. However the string in the registry cant be run directly in a cmd window because of the format errors. It has spaces without quotations, it has invalid characters, etc, etc I know things run different when executed in the registry, so maybe there is a way I can run the regsitry key just like how the system does? If so chime in. Otherwise I did this a crude way using several stringregexpreplace() functions and have it working. The solution feels so barbaric and crude that I wanted to post it so some of you guys better than me can clean up the code, maybe offer alternative ways to do it, or reduce the number of times I process the string. Here is the string right out of the registry: c:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe /Uninstall file:///C:/Users/it022565/AppData/Local/Temp/OOBAXTOWordAddIn/ApplicationXtender.AXTO.Word.vsto Here is my cave man scripting to turn this into a run able string. Func _UninstallOld() For$i = 1 to 100 ;Enumerate Registry $sEnumBase = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" ;Look in HKCU for the uninstall string for the old version$sEnum = RegEnumKey($sEnumBase,$i) If @Error Then Return If $iDebug = 1 Then MsgBox(0, "",$sEnum) If StringInStr(RegRead($sEnumBase &$sEnum, "DisplayName"), "Word Addin") Then ExitLoop Next If $iDebug = 1 Then MsgBox(0, "",$sEnum) $sKey = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" &$sEnum $sKey2 = RegRead($sKey, "UninstallString") If $iDebug = 1 Then MsgBox(0, "Original Install Location",$sKey2) $sKey3 = StringRegExpReplace($sKey2, "(?i)(c:.*exe)", '"$1"') If$iDebug = 1 Then MsgBox(0, "", $sKey3)$sKey4 = StringRegExpReplace($sKey3, "(?i)file:///", "") If$iDebug = 1 Then MsgBox(0, "", $sKey4)$sKey5 = StringRegExpReplace($sKey4, "%20", " ") If$iDebug = 1 Then MsgBox(0, "", $sKey5)$sKey6 = StringRegExpReplace($sKey5, '(?i)((?<!")c:.*vsto)', '"$1"') If $iDebug = 1 Then MsgBox(0, "",$sKey6) RunWait(@ComSpec & ' /c ' & '"' & $sKey6 & ' /s"', "", @SW_HIDE) EndFunc Basically step by step I add quotations, strip bad characters, etc. Kind of proud for using look behind for once Looking forward to what you guys come up with. • By tezhihi I have a file (see attached file) with a string all line and this problem on here is I want to separate all$00:, $03:,$10:, $20:,$25:, $30:,$40:, $45:,$110:, $115:,$120: and $T. It's mean that each$ with value start a new line ( a new paragraph). I tried with Regular Expression in notepad++ ex:
Find ($00:,$01:, $03: and so on) with regex (\$)([0-9]+): and replace is \r\n\1\2 (I think \r\n is @CRLF (not sure :() ) Find $T with regex (\$T)(.*?)(\\$T) and replace is \1\2\r\n\3 When I try these regex to replace in notepad on StringRegexReplace the results is incorrect . I have read some example simple about regex. Please advise me how to do that with some example on autoit . The result will be in attached photo. Thanks