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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:
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
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.

You can Add a comment or ranking to this page

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