Guy_ Posted September 15, 2014 Share Posted September 15, 2014 (edited) I'll always feel a n00b and therefore hesitant to post what I think is a bug... Having a first go with this one (that doesn't work in the release version either): Manual for StringRegExpReplace states: "Check @extended for the number of replacements performed" However this seems not to be happening for my _WordCount( $text ) function and I have to use _WordCount2( $text ) as a workaround. "I hope this is a real bug"...? Global $text = "Six word sentence for testing purposes." MsgBox(0,"", "The sentence '" & $text & "' has " & _WordCount( $text ) & " words." & @CRLF & _ "The sentence '" & $text & "' has " & _WordCount2( $text ) & " words." ) ; manual states: "Check @extended for the number of replacements performed" (but doesn't seem to work?) Func _WordCount( $text ) StringRegExpReplace( $text, "(\s){1,}[\W|_](\s){1,}|\R", " ", 0 ) Return @extended + 1 ; nr of spaces + 1 = wordcount EndFunc ; workaround Func _WordCount2( $text ) StringReplace( StringRegExpReplace( $text, "(\s){1,}[\W|_](\s){1,}|\R", " ", 0 ), " ", "x") Return @extended + 1 ; nr of spaces + 1 = wordcount EndFunc Edited September 15, 2014 by Guy_ Link to comment Share on other sites More sharing options...
jchd Posted September 15, 2014 Share Posted September 15, 2014 (edited) Why make it hard? Global $text = "A 8-word sentence for 365 testing purposes." MsgBox(0,"", "The sentence '" & $text & "' has " & _WordCount( $text ) & " words.") ; manual states: "Check @extended for the number of replacements performed" (but doesn't seem to work?) Func _WordCount( $text ) StringRegExpReplace( $text, "\b([[:alnum:]]+)", "") Return @extended ; nbr of words EndFunc EDIT: without uderscores allowed inside words. Edited September 15, 2014 by jchd 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...
Moderators Solution Melba23 Posted September 15, 2014 Moderators Solution Share Posted September 15, 2014 (edited) Guy_,No bug - your RegEx just does not work and so it makes no replacements. Just add some error checking and you can see what happens: expandcollapse popupGlobal $text = "Six word sentence for testing purposes." MsgBox(0,"", "The sentence '" & $text & "' has " & _WordCount( $text ) & " words." & @CRLF & _ "The sentence '" & $text & "' has " & _WordCount2( $text ) & " words." & @CRLF & _ "The sentence '" & $text & "' has " & _WordCount3( $text ) & " words." & @CRLF & _ "The sentence '" & $text & "' has " & _WordCount4( $text ) & " words." ) ; Your RegEx fails Func _WordCount( $text ) $sNewText = StringRegExpReplace( $text, "(\s){1,}[\W|_](\s){1,}|\R", "#", 0 ) $iExtended = @extended ConsoleWrite($sNewText & @CRLF) Return $iExtended + 1 ; nr of spaces + 1 = wordcount EndFunc ; This is functionally equivlent to... Func _WordCount2( $text ) $sNewText = StringReplace( StringRegExpReplace( $text, "(\s){1,}[\W|_](\s){1,}|\R", " ", 0 ), " ", "x") $iExtended = @extended ConsoleWrite($sNewText & @CRLF) Return $iExtended + 1 ; nr of spaces + 1 = wordcount EndFunc ; ...this simple StringReplace Func _WordCount3( $text ) $sNewText = StringReplace($text, " ", "x") $iExtended = @extended ConsoleWrite($sNewText & @CRLF) Return $iExtended + 1 ; nr of spaces + 1 = wordcount EndFunc ; But if you use a RegEx that actually works you get the count returned Func _WordCount4( $text ) $sNewText = StringRegExpReplace($text, "(\s+)", "#") $iExtended = @extended ConsoleWrite($sNewText & @CRLF) Return $iExtended + 1 ; nr of spaces + 1 = wordcount EndFuncAs you can see in the SciTE console, no replacements are made with your RegEx, so the count is correct. M23Edit: In future please start a new thread rather than post in the Beta thread which is used to point out specific problems with the Beta rather than generic problems like this. I will split these posts off in a while. Edit 2:And split. Edited September 15, 2014 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Guy_ Posted September 15, 2014 Author Share Posted September 15, 2014 (edited) Thank you both. This is a lesson to integrate error checking... Why make it hard? The codes are to filter out some specific stuff that I don't want to be counted as a real word. And I thought it was working too... (maybe it is in part, just not in this example with only regular spaces) Edited September 15, 2014 by Guy_ Link to comment Share on other sites More sharing options...
Guy_ Posted September 15, 2014 Author Share Posted September 15, 2014 Thx. This was my last bug report ever! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 15, 2014 Moderators Share Posted September 15, 2014 Guy_, This was my last bug report ever!By all means do report possible bugs - but as I said in your earlier thread, best to post in the forum first to get others to check. And do some in depth errorchecking yourself as well, of course. M23 Guy_ 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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