Originally posted by Duy Nguyen
Originally posted by Ryan Spires
set string "459-7600"regexp {^.*-(.*)$} $string match newStringputs $newString
Max Drown wrote:set string "459-7600"regexp {^.*-(.*)$} $string match newStringputs $newString
Max Drown wrote:
if {regexp {^.*-(.*)$} $string match newString} { # do something}else { set newString "" puts "ERROR!"}
Max Drown wrote:Yes, but you may want to add some logic for unexpected situations.For example ...if {regexp {^.*-(.*)$} $string match newString} {
Max Drown wrote:Well if you get a number with a slash or an empty string, the regexp will fail and newString will not get set. If your script then tries to access newString, which has not been set, then the script will "crash". So, you need to code for that sort of thing.
Duy Nguyen wrote:Max Drown wrote:Well if you get a number with a slash or an empty string, the regexp will fail and newString will not get set. If your script then tries to access newString, which has not been set, then the script will "crash". So, you need to code for that sort of thing.So basically I need to write something that will bypass the part where it CHECKS if the CONDITION is MET if I'm not dealing with GOOD DATA?
Duy Nguyen wrote:
Max Drown wrote:Yes.regexp returns the number of matches found. So, "if {regexp {^.*-(.*)$} $string match newString} {" will alert you if a match was found or if a match was not found (the else block).