youtuber Posted October 14, 2017 Share Posted October 14, 2017 (edited) if the user enters a double quotation marks in the input Friends content="([^"]+)" or href='([^']+)'How can I check if a single quotation marks is entered? Could there be a problem when the user enters double or single quotation marks in the input field? Or how can I read input in this case? My sample codes expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $aListRegex = "<a href='https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/'>" & @crlf & _ '<meta itemprop="url" content="https://www.autoitscript.com/forum/">' $Form1 = GUICreate("Form1", 353, 393, 363, 59) $aHtmLEdit = GUICtrlCreateEdit("", 8, 24, 321, 89) GUICtrlSetData($aHtmLEdit, $aListRegex) GUICtrlSetLimit($aHtmLEdit, 1000000) $aRegexInput = GUICtrlCreateInput("", 40, 134, 305, 21) GUICtrlSendMsg($aRegexInput, $EM_SETCUEBANNER, False, 'Please enter regex Sample : content="([^"]+)" ' & " Or " & "href='([^']+)'") $Label1 = GUICtrlCreateLabel("Regex", 5, 136, 35, 17) GUICtrlSetState($Label1,$GUI_FOCUS) $aResultEdit = GUICtrlCreateEdit("" & @CRLF, 8, 176, 321, 137, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL)) GUICtrlSetData(-1, "") GUICtrlSetLimit($aResultEdit, 1000000) $RegexTest = GUICtrlCreateButton("RegexTest", 120, 344, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $RegexTest $aReadRegexInput = GUICtrlRead($aRegexInput) $aReadHtmLEdit = StringSplit(GUICtrlRead($aHtmLEdit), @CRLF, 1) $aGetRegex = StringRegExp($aReadHtmLEdit, $aReadRegexInput,3) For $i = 0 To UBound($aGetRegex) -1 GUICtrlSetData($aReadHtmLEdit, $aGetRegex[$i] & @CRLF, 1) Next EndSwitch WEnd Edited October 14, 2017 by youtuber Link to comment Share on other sites More sharing options...
kylomas Posted October 14, 2017 Share Posted October 14, 2017 (edited) youtuber, You can capture both of these links using a pattern like this... #include <array.au3> Global $sListbox = "<a href='https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/'>" & @CRLF & _ '<meta itemprop="url" content="https://www.autoitscript.com/forum/">' $aResult = StringRegExp($sListbox, '(?i)(?:href=(?:\x22|\x27)|content=(?:\x22|\x27))([^\x22\x27]+)(?:\x22|\x27)', 3) ConsoleWrite(@error & ' - ' & @extended & @CRLF) _ArrayDisplay($aResult) If you really want to test for ' or " just use hex notation, as above, or, stringinstr. kylomas Edited October 14, 2017 by kylomas youtuber 1 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...
youtuber Posted October 14, 2017 Author Share Posted October 14, 2017 user will specify regex Not me! Link to comment Share on other sites More sharing options...
kylomas Posted October 14, 2017 Share Posted October 14, 2017 (edited) youtuber, Then let me make a couple of suggestions: 1 - Use a dropdown list to let them select which pattern they want. Eliminates typos and the need to determine which expression was selected. 2 - Use the defacto variable naming convention (a = array, s = string, etc). These are documented somewhere, although where escapes me at the moment. kylomas Edited October 14, 2017 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...
mikell Posted October 14, 2017 Share Posted October 14, 2017 youtuber, An expression written in an input to be used as a pattern doesn't need to be surrounded with quotes ; concept $input = GUICtrlCreateInput(...) $pattern = GUICtrlRead($input) $result = StringRegExp($text, $pattern, 3) But I agree with kylomas at 120% : it's highly better to suggest to the user a list of predefined expressions (combo, radio buttons, etc) so you don't have to check if the chosen pattern is valid or not Link to comment Share on other sites More sharing options...
jchd Posted October 14, 2017 Share Posted October 14, 2017 +1 and that will eleminate possibilities for hacking and nefarious purposes. 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...
youtuber Posted October 14, 2017 Author Share Posted October 14, 2017 There is a similar here Could you share an example according to the codes above? Because the example in question is too complicated for me 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