| |||||||||||
regexp for multi line matching Posted by ahmedrubbani (ahmedrubbani), 24 November 2006 Helllo Everybody,I am a new memeber of this forum and a very new to TCL programming. I need immediate help from you guys. I am sure somebody will help me out. My question is fairly basic. I am trying to write regexp that will only match the following string (When it is on a line entirely by itself.): ABC Please let me know how can I modify my program for multiple line string e.g "ads\nABC\nere". My code just to match ABC in single line is given below. PLEASE HELP ME OUT. Cheers #Initialisation set match 0; #define a string set something "ABC"; puts "STRING ENTERED: $something"; #Determine length of string (something) and store it in a set a [string length $something]; #matches the string with ABC regexp ABC $something match; #conditional check if string is ABC AND its length is 3 if {$match eq "ABC" && $a eq 3} { puts "Matched: $match"} else {puts "Not Matched";} Posted by admin (Graham Ellis), 25 November 2006 In regular expressions, ^ and $ usually match at the very start or at the vey end of an expression. However, if you use what is know as "multiline" mode, you can modify their behavious so that they match at embedded new lines. In the case of Tcl, this is done with the -lineanchor option. Thus:Code:
Posted by ahmedrubbani (ahmedrubbani), 26 November 2006 Thanks 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 |