CygnusX1 Posted December 2, 2016 Share Posted December 2, 2016 (edited) Hello, It seems I'm lousy at RegEx. I'm getting text from menus using $name = _GUICtrlMenu_GetItemText($menu, $c) Some menu text looks like, New Ctrl+N, Open Ctrl+O etc. with one space between the menu text and the shortcut letters. Some menu text looks like, Save As..., Save Copy As..., no shortcut letters. I want to get all the text up to the shortcuts e.g. Ctrl+N or Ctrl+O, I just need New, Open etc. For the life of me I can not figure out how to get just back the menu text without the shortcut letters I know people are reluctant to write code but I'm failing and I've read the documentation, I just clearly don't understand. I have tried $matches = StringRegExp($name, "(.*)(\s)", 1) Can someone please offer some help? Thank you. Edited December 2, 2016 by CygnusX1 Cygnus Link to comment Share on other sites More sharing options...
j0kky Posted December 2, 2016 Share Posted December 2, 2016 (edited) Does each shortcut have a "+" inside? Edited December 2, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
iamtheky Posted December 2, 2016 Share Posted December 2, 2016 local $aArr = ["New Ctrl+N" , "Open Ctrl+O" , "Save As...", "Save Copy As..."] For $stuff in $aArr $sRex = StringRegExpReplace($stuff , "(\s.*\+.\z)" , "") consolewrite($sRex & @CR) Next ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
CygnusX1 Posted December 2, 2016 Author Share Posted December 2, 2016 (edited) No, some menu items look like Delete Delete, Circle C, Arc A etc. Edited December 2, 2016 by CygnusX1 Cygnus Link to comment Share on other sites More sharing options...
iamtheky Posted December 2, 2016 Share Posted December 2, 2016 (edited) mine probably should have a + instead of an asterisk as there probably wouldn't be a case where there was no left side of the key combination, but I suck at regex so it's best to just wait for the good answers to show up Edited December 2, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
j0kky Posted December 2, 2016 Share Posted December 2, 2016 (edited) I don't think it is possible to write a pattern that can make: New Ctrl+N Save As Circle C equal to: New Save As Circle The best option you have is to use a Regex like the one Iamtheky suggests to clean the one with the "+" sign, and to hardcode something like: StringReplace("Source string and something else", "Source string") Edited December 2, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
GMK Posted December 2, 2016 Share Posted December 2, 2016 (edited) Are there any tabs between the menu item and the shortcut? Can you give us a return value from _GUICtrlMenu_GetItemText? Edited December 2, 2016 by GMK _GUICtrlMenu_GetItemText Link to comment Share on other sites More sharing options...
CygnusX1 Posted December 2, 2016 Author Share Posted December 2, 2016 Here are some examples of returned text. It is Swedish by the way. Arkiv &Ny Ctrl+N Ny &Öppna... Ctrl+O Öppna... &Skapa komponent... G Zoom &Fönster Ctrl+Shift+W I don't think there are tabs between the text. When I copy the text into a text editor and view spaces, tabs, LF etc. I see a dot for a space. Cygnus Link to comment Share on other sites More sharing options...
iamtheky Posted December 2, 2016 Share Posted December 2, 2016 (edited) so if it has plus signs or is something preceded by multiple spaces, it disappears? local $aArr = ["Arkiv" , "&Ny Ctrl+N" , "Ny" , "&Oppna... Ctrl+O" , "Oppna..." , "&Skapa komponent... G" , "Zoom &Fonster Ctrl+Shift+W "] For $stuff in $aArr $sRex = StringRegExpReplace($stuff , "(\s.+\+.+?\z)|(\s\s\s\s.*\z)" , "") consolewrite($sRex & @CR) Next *I altered your foreign characters so as to reflect correctly in the console Edited December 2, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
GMK Posted December 2, 2016 Share Posted December 2, 2016 (edited) This works for me: #include <GuiMenu.au3> Example() Func Example() Local $hWnd, $hMain, $hFile, $iCount ; Open Notepad Run("notepad.exe") WinWaitActive("[CLASS:Notepad]") $hWnd = WinGetHandle("[CLASS:Notepad]") $hMain = _GUICtrlMenu_GetMenu($hWnd) $hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0) $iCount = _GUICtrlMenu_GetItemCount($hFile) ; Get item text For $iItem = 0 To $iCount Writeln("Item text: " & StringRegExpReplace(_GUICtrlMenu_GetItemText($hFile, $iItem), '(?:\h{2,}|\t)\S+', '')) Next EndFunc ;==>Example ; Write a line of text to Notepad Func Writeln($sText) ControlSend("[CLASS:Notepad]", "", "Edit1", $sText & @CRLF) EndFunc ;==>Writeln Edited December 2, 2016 by GMK Forgot to declare $iCount CygnusX1 1 Link to comment Share on other sites More sharing options...
CygnusX1 Posted December 2, 2016 Author Share Posted December 2, 2016 Bravo GMK! I really appreciate your help. I'm going to dig into what the RegEx is doing so I can understand the mechanics of it and how it works. Thanks again! Cygnus Link to comment Share on other sites More sharing options...
jguinch Posted December 2, 2016 Share Posted December 2, 2016 StringRegExpReplace(_GUICtrlMenu_GetItemText($hFile, $iItem), '\t\V+', '') iamtheky 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
iamtheky Posted December 2, 2016 Share Posted December 2, 2016 jg doesn't rex that ass, he wrecks that ass! kylomas 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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