iCode Posted October 2, 2011 Share Posted October 2, 2011 i'm trying to strip any trailing space from every line of a multiline string without splitting the string using something like StringRegExpReplace($string, '(?m)\h+$', '') sample string... a [followed by a space] b [followed by a space] so it seems like any of these expressions should work, but only the last space is matched... (?m)\h+$ (?m:\h+$) (?m:\h+)$ (?m)\h+\z (?m:\h+\z) (?m:\h+)\z so \h doesn't seem like it's working in multiline mode, yet this does... (?m)\s+$ from the help file... $ assert end of string (or line, in multiline mode) and... The settings of the PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and PCRE_EXTENDED options can be changed from within the pattern by a sequence of Perl option letters enclosed between "(?" and ")". The option letters are m for PCRE_MULTILINE FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width) Link to comment Share on other sites More sharing options...
Ramzes Posted October 2, 2011 Share Posted October 2, 2011 I think this is the easiest way: #include <Array.au3> $String = "Red " & @CRLF & "Blue " & @CRLF & "Green " $String = StringSplit($String, @CRLF, 3) For $i = 0 To UBound($String) - 1 $String[$i] = StringStripWS($String[$i], 2) Next $String = _ArrayToString($String, @CRLF) MsgBox(32, "", "|" & $String & "|") Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
JohnOne Posted October 2, 2011 Share Posted October 2, 2011 StringStripWS ( "string ", 2) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jchd Posted October 2, 2011 Share Posted October 2, 2011 StringRegExpReplace($s, '\h*\r', '') 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 Melba23 Posted October 2, 2011 Moderators Share Posted October 2, 2011 iCode, Try this: StringRegExpReplace($sString, "\h*(?=\v|\z)", "")\h* - any number of horizontal whitespace characters (?=\v|\z) - which are followed by either a vertical whitespce or an end of string.That seems to work even if there are multiple spaces at the end of the lines or additional spaces within them. M23 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...
iCode Posted October 2, 2011 Author Share Posted October 2, 2011 (edited) i should have specified that i don't want to strip vertical spaces, so none of the above will work, except... @Melba23 - ?= positive look ahead is a weak point for me - i changed yours a bit (* to +) and this seems to doing what i want... \h+(?=\v|\z) thanks for that! so this is is pretty close to what i wanted to build - matches string beginning space(s), string ending space(s) and beginning and ending horiz space(s) for each line... (?m:^\h+)|\h+(?=\v|\z) would be cool i think to have 2 options added to StringStripWS() * strip all horizontal space for beginning of every line * strip all horizontal space for end of every line actually this works even better... ^\s+|(?m:^\h+)|\h+(?=\v|\z)|\s+$ Edited October 2, 2011 by iCode FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 2, 2011 Moderators Share Posted October 2, 2011 iCode, You can do that with a simple wrapper function as Ramzes showed above so I doubt your suggestion woudl meet with much success. From the Feature Request Guidelines: Think about your feature request. If you can do it via UDFs, then don't ask for it to be built in. There's a reason you can create your own functions. M23 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