About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Metacharacters...

   Browse by title articles:
   What is hot:

Accessing Arrays

Sorting Arrays

Push and Pop

Exploding and Imploding

Regular Expressions

Metacharacters

See How To Troubleshoot Your Power Supply
Building Printer Friendly Pages
Hard Drive Does Not Boot
The 3 Musts for Running Your Web Design Business Efficiently and Effectively
Prev articles12345678 9 101112Next articles



Metacharacters


Computer & I'net articlesMetacharacters

by David Stanley    



Metacharacters are special add-on things for doing a search. Keeping the z as our example to search for, here is a list of different metacharacters you can use...

^z searches for a part that begins with z.
z$ searches for a part that ends with z.
z+ searches for at least one z in a row.
z? searches for zero or one z.
(yz) searches for yz grouped together.
y|z searches for y or z.
z{3} searches for zzz.
z{1,} searches for z or zz or zzz and so on...
z{1,3} searches for z or zz or zzz only.

Other metacharacter type searches include...

. searches for ANY character or letter.
[a-z] searches for any lowercase letter.
[A-Z] searches for any uppercase letter.
[0-9] searches for any digit 0 to 9.
escapes the next character.
new line.
tab.

The escape is used if you want to include a special character in the search itself. These are ^.[]$()|*?{}. Since these characters in used as search commands, if you need to search for that character itself, you need to put the escape in front of it. For example... if you need to search for a dollar sign, it would look like $ instead of just the dollar sign. The dollar sign by itself would create a search that ends with something.

These search parameters can be used alone or in combinations. A real world example would be to look at an email address and check to see if it seems to be valid or not.

A seemingly valid email address (someone@someplace.com) contains :
1. An unknown amount of letters or numbers. .+
2. The @ symbol. @
3. An unknown amount of letters or numbers. .+
4. A period.. (Remembering to escape it.)
5. Some ending characters. .+

This will not actually check to see if the email itself is a working one, but at least it will check to see if it qualifies to be an email address to begin with.

<?php
$value1 = "here@there.com";
$value2 = "here@there.ca";
$value3 = "here@therecom";

$search_pattern = ".+@.+..+";

$result1 = eregi($search_pattern,$value1);
$result2 = eregi($search_pattern,$value2);
$result3 = eregi($search_pattern,$value3);

if ($result1) {echo "one is true. ";} else {echo "one is false. ";}
if ($result2) {echo "two is true. ";} else {echo "two is false. ";}
if ($result3) {echo "three is true.";} else {echo "three is false.";}
?>

one is true. two is true. three is false.

Using these metacharacters and a pair of (parentheses) you can create a number of different and complex search patterns. Here are some examples of different search patterns :

abc{3} searches for abccc
(abc){3} searches for abcabcabc
on|off searches for onff or ooff
(on)|(off) searches for on or off



-----------------
Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.





Credit card




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com