| |||||||||||
RegEXP Posted by technocrat2004 (technocrat2004), 17 February 2006 Hi friends,I have two strings as below: "IA - OSPF inter area route, E1 - OSPF external type 1” set to arg1 “[120/16]” set to arg2 when i try regexp to match arg2 to arg1 i am getting a 1 as return value. Can any one help me to trace what is happening. Here you have the dump:....... expect1.4> set line "IA - OSPF inter area route, E1 - OSPF external type 1" IA - OSPF inter area route, E1 - OSPF external type 1 expect1.5> set arg "\[120/16]" [120/16] expect1.6> puts $arg [120/16] expect1.7> puts $line IA - OSPF inter area route, E1 - OSPF external type 1 expect1.8> regexp $arg $line match 1 expect1.9> puts $match 1 Posted by Custard (Custard), 17 February 2006 I'm not a tcl regexp expert (at the moment, used to be, but more perl now) but it looks a little like the arg1 '[120/16]' is a character class, and probably matched the first occurrence of the digit '1' from the class.. (I need to look it up to verify this)What is it you are trying to match? Are you looking for a string '120/16' in the $line ? And what would you like in $match after the regexp? Bruce Posted by technocrat2004 (technocrat2004), 17 February 2006 Tahnk you for the reply bose........I want to match "[120/16]" in the line. That is why i had set arg1 as set "\{120/16]". If I am wrong at any point please correct me as i am also new to regexp... As far as I know in tcl we have everything as string.... so "[120/16]" should come as sting. And I am matching this string to $line. Also regexp should return if there is a full match of arg1 to arg2..... Friends, please let me know if i am correct... if yes why I am getiing 1 as return value...... if no please expelain.... Yours Loving Technocrat...... Posted by admin (Graham Ellis), 18 February 2006 You're wanting to match a [ character literally as part of a regular expression using Tcl .... but the [ is a "special" twice over so it need double protection. Let me explain.Firstly, [ through ] mean "run this first" to the Tcl interpretter; to avoid this happening, you can wrap them in { through } or in " through " or protect them with a preceeeding \. Secondly [ through ] in a regular expression means that you're looking for any 1 character from within the square brackets, and if you want to match literally you need an extra \ protection, remembering that the \ will also need protection from the Tcl interpretter. Here are two solutions to illustrate this - the first uses { through } to defer the regular expression so that any \ characters in it do NOT ned further protection from the Tcl interpretter; the second uses " through " to group the regular expression and in this case the \ does need extra protection. Code:
Posted by technocrat2004 (technocrat2004), 20 February 2006 Thank you Bose.................................Thank you very much................................ I got the point 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 |