Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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.):

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.

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:

set samples [list "Hello world\nABC\nThis matches" \
       "Another test\nABCD\nNo match" ]

foreach sample $samples {
       puts [regexp -lineanchor {^ABC$} $sample]

Posted by ahmedrubbani (ahmedrubbani), 26 November 2006

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho