Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/19/2023 in all areas

  1. Here's another way to do it: https://regex101.com/r/kCDJ2E/2 I also like using this site (regex101) as it has some description of what's happening in the right toolbar, and common tokens and expressions as well. So it can explain the regex better than I can, but basically: <\/?a\b[^>]*?\/?> < - Matches < \/? - Escapes "/" and matches it 0 or 1 times with "?" a - Match your a tag \b - Word boundary, meaning that it'll match only the previous character is followed by a non-word character, like whitespace or _ [^>] - Matches any character that ISN'T (because of ^) in the character set, so just the ">" character. It continues matching on NOT ">" between 0 and unlimited (*) times, returning the first time it finds a match \/? - Match a tag like <a href="meow" /> with a trailing /. Escapes "/" and matches it 0 or 1 times with "?" > - Ends our pattern by finally matching on the first ">" found. I'm not the best at regex either, but I use it often. This above information is just from my understanding of it, but if you want more information I would definitely check out the description that is given on the regex101 page. Edit: Be sure to also check out the AutoIt options for RegEx, especially this one: (?i) From the helpfile for (?i): Caseless: matching becomes case-insensitive from that point on. This way you can match on <A> or <a>. So my provided pattern would look like this: $sPattern = "(?i)<\/?a\b[^>]*?\/?>"
    3 points
  2. You already did great with your test, that's why you shouldn't give up your efforts and keep on testing simple patterns. It's the way to improve, slowly, your knowledge with RegEx . I'm feeling same constantly (and probably plenty of users here too) because our knowledge in RegEx is very limited, compared to some gurus on this Forum who can construct quickly powerful patterns. If you don't mind, I would like to discuss your pattern, to eliminate from it what could be superfluous. Here are your original subject & pattern : Leave <anyother> in. This is a string that contains <a id=something>multiple</a> instances of the <a href=another thing>codes</a> that I want to strip out. (</?a[ ].*?>)|(</a>) (In everything that follows, I'll surround with simple quotes every piece of the pattern we're gonna discuss, so it will be clearly visible, for example ' ' for a space or '<a ' for the 3 characters surrounded by the simple quotes. Please think of these simple quotes as 'Forum visual delimiters' , they're not part of the real pattern) You used the pipe symbol '|' which means OR (e.g. named alternation) It's ok with that, because you're searching '<a ...>' or '</a>' So you wanna match the first '<' followed by 'a' followed by 1 space ' ' Then you can simply start your pattern like this, with 3 characters : '<a ' Now you want to grab each and every character until the corresponding closing '>' is found. To do this : => The dot '.' matches any character (except newlines characters by default, we won't discuss it here) => The star quantifier * will repeat the precedent character 0 or more times. => And you want a closing '>' at the end of the match. Then you think : "great, I'll construct my pattern easily ( the part before '|' ) just like this" : '<a .*>' Unfortunately, this didn't work, as you discovered it by yourself (which is great for your knowledge) : This is because the star quantifier '*' is greedy by default. Though it found the 1st closing '>' you were interested in... it kept on searching through the whole subject if there are others '>' . When it found the very last '>' then it matches an endless string starting with the 1st '<a ' and ending with the very last '>' which is not what you want at all. There is a simple way to make the star '*' ungreedy (aka lazy) , it will order the engine to stop searching after it found the very first closing '>' . A question mark '?' placed just after '*' makes the star quantifier ungreedy (as you correctly added it in your original pattern), so now your correct pattern on the left side of the alternation '|' is functional : '<a .*?>' The rest is easy as 1-2-3, a pipe symbol '|' followed by a simple '</a>' '<a .*?>|</a>' This is what this pattern returns (4 matches) before the Replace process : Then you use it directly in the Replace function, replacing all matches with an empty string... $sAfter = StringRegExpReplace($sBefore, '<a .*?>|</a>', '') ...which will correctly output like this : Leave <anyother> in. This is a string that contains multiple instances of the codes that I want to strip out. I hope it's a bit clearer now : no need of groups in your case, e.g. '(...)' or character classes '[ ]' or the optional '/?' as found in your original pattern. Guys, if I wrote something incorrect, please don't hesitate to indicate it. Thanks for reading
    2 points
  3. and You're right, that site is very helpful for explaining the voodoo that you do. And your explanation in the post, once I took the time to dissect it, makes sense. However, one part of your pattern seems superfluous, but please correct me if I'm mistaken: The '[^>]' grouping says to match any character that is NOT a '>', and since it's followed by '*?' (0 or more, lazy) that means it will take either 0 or as many characters as there are up until it comes to the next '>' character. Since a '/' character would already be matched by that, I think the next '\/?' code to look specifically for a '/' isn't needed. And in fact, removing that '\/?' bit doesn't prevent it from matching your '<a href="meow" />' example. So it seems this will suffice, unless I'm mistaken: $sPattern = "(?i)<\/?a\b[^>]*?>"
    1 point
  4. If you must, you can do it using the Assign() function and you can read the dynamically created global variable with the Eval() function. Example: #include <Constants.au3> Const $IniGroup = "Main", _ $IniProp = "Path" example() ConsoleWrite("Setup_" & $IniGroup & "_" & $IniProp & " = " & Eval("Setup_" & $IniGroup & "_" & $IniProp) & @CRLF) Func example() ;Create and assign a value to a dynamically created variable name Assign("Setup_" & $IniGroup & "_" & $IniProp, "Some Value", $ASSIGN_FORCEGLOBAL) EndFunc Console: Setup_Main_Path = Some Value
    1 point
  5. @ScorpX,That question was asked two posts above yours, and answered by @Danyfirex, "Check Example 4".
    1 point
  6. #RequireAdmin #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator If Not WinExists("Local Group Policy Editor") Then ShellExecute("C:\WINDOWS\SYSTEM32\MMC.EXE", "C:\WINDOWS\SYSTEM32\GPEDIT.MSC") WinWait("Local Group Policy Editor", '', 5) EndIf ;Retrieves the 'Local Group Policy Editor' window handle Global $hGPO = WinActive("Local Group Policy Editor") ConsoleWrite("$hGPO=" & $hGPO & @CRLF) ;Retrieves the SysTreeView321 control handle Global $hTreeView_1 = ControlGetHandle($hGPO, "", "SysTreeView321") Global $sPolicyPath, $sPolicyItem $sPolicyPath = "\Computer Configuration\Administrative Templates\All Settings" $sPolicyItem = "Allow Adobe Flash" $sPolicyPath = "Local Computer Policy" & $sPolicyPath ConsoleWrite("$sPolicyPath=" & $sPolicyPath & @CRLF) ConsoleWrite("$sPolicyItem=" & $sPolicyItem & @CRLF) Global $aPath = StringSplit($sPolicyPath, "\", 1) Global $tmpPath = "" ConsoleWrite("" & @CRLF) For $i = 1 To $aPath[0] $tmpPath &= $aPath[$i] & "|" ConsoleWrite("$tmpPath=" & StringTrimRight($tmpPath, 1) & @CRLF) ControlTreeView($hGPO, "", $hTreeView_1, "Expand", StringTrimRight($tmpPath, 1)) ControlTreeView($hGPO, "", $hTreeView_1, "Select", StringTrimRight($tmpPath, 1)) Sleep(50) Next ;at the bottom tabs we go right to the standard tab ControlFocus($hGPO, "", "AMCCustomTab1") ControlSend($hGPO, "", "AMCCustomTab1", "{RIGHT}") Sleep(50) ;Retrieves the SysListView321 control handle Global $hListView = ControlGetHandle($hGPO, "", "SysListView321") ;Sets the focus to SysListView321 ControlFocus($hGPO, "", $hListView) Global $Item, $ItemCnt, $ItemTxt, $FindItem ;Selects the first items. ControlListView($hGPO, "", $hListView, "Select", 0) ;~ ControlSend($hGPO, "", $hListView, "{HOME}") ;Returns a string containing the item index of selected items $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & @CRLF) Sleep(50) ;Returns the number of list items. $ItemCnt = ControlListView($hGPO, "", $hListView, "GetItemCount") ConsoleWrite("$ItemCnt=" & $ItemCnt & @CRLF) Sleep(50) ;Returns the item index of the string. Returns -1 if the string is not found $FindItem = ControlListView($hGPO, "", $hListView, "FindItem", $sPolicyItem) ConsoleWrite("$FindItem=" & $FindItem & @CRLF) Sleep(50) For $x = 0 To $ItemCnt - 1 ControlListView($hGPO, "", $hListView, "Select", $x) $SelectedItem = ControlListView($hGPO, "", $hListView, "GetSelected") ConsoleWrite("$SelectedItem=" & $SelectedItem & " ") $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 3) ConsoleWrite("$ItemTxt=" & $ItemTxt & @CRLF) If $x = $FindItem Then ExitLoop Sleep(100) Next ConsoleWrite("" & @CRLF) $ItemTxt = ControlListView($hGPO, "", $hListView, "GetText", $SelectedItem, 0) ConsoleWrite("--> found " & $ItemTxt & @CRLF) ConsoleWrite("" & @CRLF) look at console out
    1 point
  7. like that <image>
    1 point
  8. (</?a.*?>) This should resolve that issue. Did my testing with just a single <a> tag.
    1 point
  9. You guys are absolutely amazing Thank you both for this solution, it works like a charm! Unfortunately I can only mark a single post as solution So I marked Melba's post as the solution and pixelsearch's post got a like
    1 point
  10. argumentum

    Opt(SetExitCode,0/1)

    We get new features but the awareness does not propagate and become common knowledge fast enough so, here is an example of use: Opt("SetExitCode", 1) OnAutoItExitRegister("__OnAutoItExit") Example() Func Example() Local $n, $a[6] = [5, 5, 4, 3, 2, 1] For $n = 1 To 100 ToolTip('..crashing in ' & $a[$n], 50, 50, "CrashTest") ConsoleWrite('..crashing in ' & $a[$n] & @CRLF) Sleep(500) Next EndFunc ;==>Example Func __OnAutoItExit() Local $sExitMethod Switch @exitMethod Case 0 $sExitMethod = "closed by natural closing." Case 1 $sExitMethod = "closed by Exit function." Case 2 $sExitMethod = "closed by clicking on exit of the systray." Case 3 $sExitMethod = "closed by user logoff." Case 4 $sExitMethod = "closed by Windows shutdown." Case Else $sExitMethod = "closed by no clue." EndSwitch ;~ If @exitCode Then MsgBox(262144, @ScriptName, "I could do something with the error from here", 2) MsgBox(262144, @ScriptName, "Oh !, wait, we now can =)" & @CR & _ @CR & "The error was: " & Hex(@exitCode) & _ @CR & "Meaning: """ & FatalErrormessageFromExitCode(@exitCode) & """" & _ @CR & "and the ExitMethod was """ & $sExitMethod & """" & _ @CR & @CR & " =)", 60) EndFunc ;==>__OnAutoItExit Func FatalErrormessageFromExitCode($iExitCode) ; from the help file Local $sExitCode = 'uncatalogued event' Switch $iExitCode Case 0x7FFFF068 $sExitCode = '"EndWith" missing "With". ' Case 0x7FFFF069 $sExitCode = 'Badly formatted "Func" statement. ' Case 0x7FFFF06A $sExitCode = '"With" missing "EndWith". ' Case 0x7FFFF06B $sExitCode = 'Missing right bracket '') '' in expression. ' Case 0x7FFFF06C $sExitCode = 'Missing operator in expression. ' Case 0x7FFFF06D $sExitCode = 'Unbalanced brackets in expression. ' Case 0x7FFFF06E $sExitCode = 'Error in expression. ' Case 0x7FFFF06F $sExitCode = 'Error parsing function call. ' Case 0x7FFFF070 $sExitCode = 'Incorrect number of parameters in function call. ' Case 0x7FFFF071 $sExitCode = '"ReDim" used without an array variable. ' Case 0x7FFFF072 $sExitCode = 'Illegal text at the end of statement (one statement per line). ' Case 0x7FFFF073 $sExitCode = '"If" statement has no matching "EndIf" statement. ' Case 0x7FFFF074 $sExitCode = '"Else" statement with no matching "If" statement. ' Case 0x7FFFF075 $sExitCode = '"EndIf" statement with no matching "If" statement. ' Case 0x7FFFF076 $sExitCode = 'Too many "Else" statements for matching "If" statement. ' Case 0x7FFFF077 $sExitCode = '"While" statement has no matching "WEnd" statement. ' Case 0x7FFFF078 $sExitCode = '"WEnd" statement with no matching "While" statement. ' Case 0x7FFFF079 $sExitCode = 'Variable used without being declared. ' Case 0x7FFFF07A $sExitCode = 'Array variable has incorrect number of subscripts or subscript dimension range exceeded. ' Case 0x7FFFF07B $sExitCode = 'Variable subscript badly formatted. ' Case 0x7FFFF07C $sExitCode = 'Subscript used on non-accessible variable. ' Case 0x7FFFF07D $sExitCode = 'Too many subscripts used for an array. ' Case 0x7FFFF07E $sExitCode = 'Missing subscript dimensions in "Dim" statement. ' Case 0x7FFFF07F $sExitCode = 'No variable given for "Dim", "Local", "Global", "Static" or "Const" statement. ' Case 0x7FFFF080 $sExitCode = 'Expected a "=" operator in assignment statement. ' Case 0x7FFFF081 $sExitCode = 'Invalid keyword at the start of this line. ' Case 0x7FFFF082 $sExitCode = 'Array maximum size exceeded. ' Case 0x7FFFF083 $sExitCode = '"Func" statement has no matching "EndFunc". ' Case 0x7FFFF084 $sExitCode = 'Duplicate function name. ' Case 0x7FFFF085 $sExitCode = 'Unknown function name. ' Case 0x7FFFF086 $sExitCode = 'Unknown macro. ' Case 0x7FFFF088 $sExitCode = 'Unable to get a list of running processes. ' Case 0x7FFFF08A $sExitCode = 'Invalid element in a DllStruct. ' Case 0x7FFFF08B $sExitCode = 'Unknown option or bad parameter specified. ' Case 0x7FFFF08C $sExitCode = 'Unable to load the internet libraries. ' Case 0x7FFFF08D $sExitCode = '"Struct" statement has no matching "EndStruct". ' Case 0x7FFFF08E $sExitCode = 'Unable to open file, the maximum number of open files has been exceeded. ' Case 0x7FFFF08F $sExitCode = '"ContinueLoop" statement with no matching "While", "Do" or "For" statement. ' Case 0x7FFFF090 $sExitCode = 'Invalid file filter given. ' Case 0x7FFFF091 $sExitCode = 'Expected a variable in user function call. ' Case 0x7FFFF092 $sExitCode = '"Do" statement has no matching "Until" statement. ' Case 0x7FFFF093 $sExitCode = '"Until" statement with no matching "Do" statement. ' Case 0x7FFFF094 $sExitCode = '"For" statement is badly formatted. ' Case 0x7FFFF095 $sExitCode = '"Next" statement with no matching "For" statement. ' Case 0x7FFFF096 $sExitCode = '"ExitLoop/ContinueLoop" statements only valid from inside a For/Do/While loop. ' Case 0x7FFFF097 $sExitCode = '"For" statement has no matching "Next" statement. ' Case 0x7FFFF098 $sExitCode = '"Case" statement with no matching "Select" Or "Switch" statement. ' Case 0x7FFFF099 $sExitCode = '"EndSelect" statement with no matching "Select" statement. ' Case 0x7FFFF09A $sExitCode = 'Recursion level has been exceeded - AutoIt will quit to prevent stack overflow. ' Case 0x7FFFF09B $sExitCode = 'Cannot make existing variables static. ' Case 0x7FFFF09C $sExitCode = 'Cannot make static variables into regular variables. ' Case 0x7FFFF09D $sExitCode = 'Badly formated Enum statement ' Case 0x7FFFF09F $sExitCode = 'This keyword cannot be used after a "Then" keyword. ' Case 0x7FFFF0A0 $sExitCode = '"Select" statement is missing "EndSelect" or "Case" statement. ' Case 0x7FFFF0A1 $sExitCode = '"If" statements must have a "Then" keyword. ' Case 0x7FFFF0A2 $sExitCode = 'Badly formated Struct statement. ' Case 0x7FFFF0A3 $sExitCode = 'Cannot assign values to constants. ' Case 0x7FFFF0A4 $sExitCode = 'Cannot make existing variables into constants. ' Case 0x7FFFF0A5 $sExitCode = 'Only Object-type variables allowed in a "With" statement. ' Case 0x7FFFF0A6 $sExitCode = '"long_ptr", "int_ptr" and "short_ptr" DllCall() types have been deprecated. Use "long*", "int*" and "short*" instead. ' Case 0x7FFFF0A7 $sExitCode = 'Object referenced outside a "With" statement. ' Case 0x7FFFF0A8 $sExitCode = 'Nested "With" statements are not allowed. ' Case 0x7FFFF0A9 $sExitCode = 'Variable must be of type "Object". ' Case 0x7FFFF0AA $sExitCode = 'The requested action with this object has failed. ' Case 0x7FFFF0AB $sExitCode = 'Variable appears more than once in function declaration. ' Case 0x7FFFF0AC $sExitCode = 'ReDim array can not be initialized in this manner. ' Case 0x7FFFF0AD $sExitCode = 'An array variable can not be used in this manner. ' Case 0x7FFFF0AE $sExitCode = 'Can not redeclare a constant. ' Case 0x7FFFF0AF $sExitCode = 'Can not redeclare a parameter inside a user function. ' Case 0x7FFFF0B0 $sExitCode = 'Can pass constants by reference only to parameters with "Const" keyword. ' Case 0x7FFFF0B1 $sExitCode = 'Can not initialize a variable with itself. ' Case 0x7FFFF0B2 $sExitCode = 'Incorrect way to use this parameter. ' Case 0x7FFFF0B3 $sExitCode = '"EndSwitch" statement with no matching "Switch" statement. ' Case 0x7FFFF0B4 $sExitCode = '"Switch" statement is missing "EndSwitch" or "Case" statement. ' Case 0x7FFFF0B5 $sExitCode = '"ContinueCase" statement with no matching "Select" Or "Switch" statement. ' Case 0x7FFFF0B6 $sExitCode = 'Assert Failed! ' Case 0x7FFFF0B8 $sExitCode = 'Obsolete function/parameter. ' Case 0x7FFFF0B9 $sExitCode = 'Invalid Exitcode (reserved for AutoIt internal use). ' Case 0x7FFFF0BA $sExitCode = 'Variable cannot be accessed in this manner. ' Case 0x7FFFF0BB $sExitCode = 'Func reassign not allowed. ' Case 0x7FFFF0BC $sExitCode = 'Func reassign on global level not allowed. ' EndSwitch Return SetError(0, $iExitCode, $sExitCode) EndFunc ;==>FatalErrormessageFromExitCode #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/mo #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.16.1 #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here Opt("SetExitCode", 1) If $CmdLine[0] = 0 Then ; https://www.autoitscript.com/autoit3/docs/appendix/Exitcodes.htm ; for CUI compile, adding "/ErrorStdOut" will write out the line number and error description" ; "(8) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:" MsgBox(262144, "ExitCode:", "0x" & Hex(RunWait('"' & @AutoItExe & '" /ErrorStdOut ' & (@Compiled ? '' : '"' & @ScriptFullPath & '" ') & '/crash')), 8) ElseIf $CmdLine[1] = "/crash" Then $CmdLine[100] = "hmmm" EndIf Edit: There are wrapper functions in v3.3.16.1 but did not know, otherwise I'd have saved me the coding. These func. are _FormatAutoItExitCode() and _FormatAutoItExitMethod() . I created the post after reviewing my tracs and decided to bla, bla, bla ... , and posted
    1 point
  11. Thank you - the file has exposed 2 cases that were not covered before. I have uploaded the new fixed version. Apart from that, the file is creepy. Data is only in the first 24 columns but there are 265 columns defined. This is probably due to the fact that someone has wildly scrolled through and first assigned a formatting to all these cells although there is nothing in it. Remove the columns and the handling of the file should be much smoother.
    1 point
×
×
  • Create New...