| |||||||||||
Simple question (sorry) Posted by eliasson (eliasson), 29 April 2008 Hello,I'm having a problem (newbie again) with regsub (and regexes in general, beginning to hate them). I do the following: # Clean up output from utility. set lineList [split $expect_out(0,string) \x1b] foreach j $lineList { regsub {\x3b} $j "" j regsub {[0-9]+} $j "" j regsub {\x5b} $j "" j regsub {[G-L]} $j "" j puts $:utfile $j } and this works just fine. But I would like to combine the regsubs into one line & I think that's possible? However, every grouping I've tried with []s, ()s, {}s, on a single line hasn't worked for me. What should this line look like? TIA, Posted by eliasson (eliasson), 2 May 2008 Nevermind, I've got it down to 2 lines. To clean up this buffer:[41;9Hgetdark 7 [42;1H[K[43;1Hgetdarkondark : Get the current on/off state of the Reflective Memory board's[44;1H[K[45;1H Dark On Dark feature[46;1H[K[47;1HUsage: getdarkondark[48;1H[K[49;1H[K[50;9H [50;9H I split into lines based on the 'esc's: set lineList [split $workBuff \x1b] Then clean each line as follows: foreach j $lineList { regsub "\[\[0-9]+;\[0-9]+\[H-L]+" $j "" j regsub "\[\[H-L]+" $j "" j } The second 'regsub' line is needed to remove '[K', I'm not sure why. But this works for now. Posted by admin (Graham Ellis), 3 May 2008 on 05/02/08 at 20:54:35, eliasson wrote:
Probably because regsub only works on the first match in a line by default. Try the -all option. Posted by eliasson (eliasson), 5 May 2008 Well, I appreciate the assist, but no, -all didn't help. I guess it must be something to do with the telnet buffer layout, but I don't know what. I'm also having probs searching for () as literals. I expect \( to 'literalize' :^) the (, but I keep getting a failure of unbalanced ()s. So, I keep looking for ways to deal ...Thx, Anders Posted by admin (Graham Ellis), 7 May 2008 Hi, Anders. For the round brackets, you need either to use a deferred block and then protect them from the regular expression handler's special meaning for them, or use double quotes and provide double protection. Here's an example:Code:
See http://www.wellho.net/resources/ex.php4?item=t205/brax. Posted by eliasson (eliasson), 15 May 2008 Many thanx, I'll work with this :^).Anders This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |