Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Matching within multiline strings, and ignoring case in regular expressions

Regular Expressions are powerful matching tools and you can specify almost anything within them. But there are certain facilities that are naturally applied to the regular expression as a whole rather than to parts of the match, and there are specified in a different way in each language / implementation.

For example, in what is commonly known as multiline mode you may want to match not only at the start / end of the string as a whole, but also match at embedded new lines. You can specify multiline mode as follows:

In Tcl, using the -lineanchor option
In Perl, with the /m modifier on the end of your regex
In Python by adding re.M or re.MULTILINE to your compile

Here's an example, in Tcl, looking for embedded lined containing just ABC:

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

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



ther facilities often added onto your regular expression as modifiers include:

a) The ability to have "." (the dot) match any character at all, and not to exclude the newline character which it does by default. Sometimes known as single line of linestop mode.

In Tcl, leave off the -linestop option
In Perl, add /s
In python, add re.DOTALL onto the compile

b) The ability to ignore case in the match

In Perl, /i
In Python, re.I or re.IGNORECASE
In Tcl, use (?i through ) in the regex

c) The ability to add white space as comments into your expression

In Perl, /x
In Python, re.VERBOSE
In Tcl, use (?X through ) in the regex
(written 2006-11-25 05:48:56)

 
Associated topics are indexed under
P212 - Perl - More on Character Strings
Q803 - Object Orientation and General technical topics - Regular Expressions - Extra Elements
T205 - Tcl/Tk - String Handling in Tcl
T247 - Tcl/Tk - Advanced Regular Expressions
Y108 - Python - String Handling

Back to
Index of Pictures
Previous and next
or
Horse's mouth home
Forward to
Just ******* Google it
Some other Articles
What is an SQL injection attack?
Look around this mouth.
Code quality counts
Just ******* Google it
Matching within multiline strings, and ignoring case in regular expressions
Index of Pictures
Snagging
Winter at Well House Manor - Open Houses
Swipe cards for hotel rooms - Security issues
Bratton and Edington new town, Wiltshire
2258 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

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