delete part of string (word) in tcl -


in tcl have variable (string) witch come input text file. many... thing going faced on :

  a1 = lp89slc.at271300.0  a2 = lp89slc.at28742.0  a3 = lp89slc.at2-71300.0  a3 = lp89slc.at2-0.260-0.085 

all of them have same part in meddle of string ({...}+{.at2}+{...}) ==> (.at2) want delete right part come next of (.at2) example :

 a1 = lp89slc.at271300.0  ==> lp89slc.at2 a2 = lp89slc.at2-71300.0 ==> lp89slc.at2 

also want know there way can delete last part of string come next special character ...at2... example : after set unpredictable variable {somecharecter.at2undesirablepart} change {somecharecter.at2}

the difference between question , first 1 that, in first situation, first part finite , assignable. in second question both part come in left , right place of {at2} unpredictable.

trim trimright trimleft commands dont job!

the easiest way use regular expression substitution:

regsub -all -line {^.*\y(\w+\.at2).*$} $thestring {\1} thestring 

the tricky bits here -line option (which makes work when applied multi-line string) , \y in regular expression (which matches @ start or end of word — it's start in case because \w must match next).


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -