Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Don't expose your regular expressions
If you're writing an application, it's generally NOT a good idea to take a user input and slap it straight in to a regular expression for matching - quite simply because it's improbable that your user will be familiar with regular expressions and he / she will get all sorts of strange results if she / he puts any special characters into their search string.

Users do often require to enter various search patterns, and I recommend that you come up with a scheme that suits your own type of search; that might involve taking the user's input and using it to indirectly for a regular expression, or it might make for some totally different search.

I was talking about this yesterday to a Perl group, with a user community that's used to using * and ? in file name matching (know as globbing) and who want to do the same on data within Perl. It's a good example where the program shouldn't just pass through the data entered - rather, they should
1. Protect input special characters with a \
2. replace input ? characters with a .
3. replace input * characters with a .*
4. Add ^ and $ anchors

And that will give them the ability to wildcard in the good ole way they wish!
(written 2006-02-15 07:00:34)

 
Associated topics are indexed under
H107 - String Handling in PHP
P212 - Perl - More on Character Strings

Back to
On being British
Previous and next
or
Horse's mouth home
Forward to
Been on a course, but still not got it?

Some other Articles
Coming or going?
Look out for the motor cyclist
Need a hankie
Been on a course, but still not got it?
Don't expose your regular expressions
On being British
Train service from December
Design your day with a walk
Perl - multiprocess applications
PHP - setting sort order with an associative array
1637 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 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., 2008: 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