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))
"AND" and "OR" in regular expressions

Posted by enquirer (enquirer), 11 September 2003
I am very new to regular expressions and I have managed to build a simple search using Case sensitivity, folder selection a logical OR statement. But, how do you perform a logicalAND.I am using ASP and I am very stuck.

Posted by admin (Graham Ellis), 11 September 2003
If you want to look for a string that contains both abc and def (for example), write
(that's dot star between the abc and def), and that will match if the input string contains abc followed later by def.

If you don't know whether the abc or def will come first (if, for example, you're writing a search algorithm to find pieces of data that contain every one of a number of elements), don't try and write a single complicated regular expression - write a loop instead.  I don't
know what language you're using within ASP - personally I like Perl; here's a Perl example that checks if a text string contains abc and def:

@want = ("abc","def");
$lookintext = "This is the text that definitely contains abc";
$matched = 1;
foreach $current (@want) {
                   $matched = 0 if ($lookintext !~ /$current/) ;

Works for any number of search strings in any order, and returns you a variable called $matched with a true value (1) if it matches all, false (0) otherwise.

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.

1 unpublished comment pending on this page

edit your own (not yet published) comments

© 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: • WEB: • SKYPE: wellho