Article Diary - General Knowledge Digest

8 Basics of Regular Expressions

Regular expressions have been something that I was scared of when I started coding as a serious stuff. The string literals puzzled me like anything. preg_match, preg_grep, preg_split, preg_replace etc have been something I always wanted to avoid. This is for you guys who find regular expressions tacky.

1. “^tech

Searches a string that starts with tech.

2. “logy$”

Searches for strings that ends up in logy.

3. “a*b”

Looks for a string that has either zero or more a’s but exactly one b following a. (eg. b, ab, aab, aaab, aaaaaaaaaaaaaaaaab etc.).

4. “a+b”

Same as a*b but only difference is that atleast one a should be there in the string unlike a*b which can overlook a. (eg. ab, aab,aaaaaaaaab etc).

5. “a?b”

In this case string might have either zero or a single a (eg. ab or b) only these two possibilities are there.


To quantify the characters into certain sets and utilize them we can use paranthesis().

6. “(abc)+def”

Matches a string which consists of pattern having abc either one or n times followed by def at the end.


7. “(a|b)*c”

A string of a and b that ends in a c.

To specify range of characters. For instance to match that in a password small-case character, you can specify the set as [a-z] or [A-Z] or [0-9].

8. “([a-z])|([A-Z])”

Searches for a pattern having either small-case or capital letters.
Attached Files
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Security Code Security Code
Related Articles RSS Feed
Lorem Ipsum Dolor Sit Amet
Viewed 1301 times since Tue, Oct 6, 2009
Google Web Toolkit - Version 2 Released
Viewed 993 times since Tue, Dec 15, 2009
ProFolio - Instantly Create Free Portfolio Website
Viewed 1375 times since Sun, Jan 3, 2010
dTree - Flexible JavaScript Tree Menu
Viewed 1430 times since Thu, Jan 14, 2010
How to protect specific folder or disable directory browsing using htaccess?
Viewed 4691 times since Sun, Mar 14, 2010
Meerkat - jQuery Plugin for Promotional Content
Viewed 957 times since Tue, Dec 29, 2009
Plupload - Multiple Files Upload Script
Viewed 1272 times since Tue, Feb 9, 2010
Best Free Web Icons for Different Purposes
Viewed 1084 times since Mon, Dec 28, 2009
What is jQuery?
Viewed 829 times since Tue, Dec 1, 2009
Stylish Cross-Browser CSS Buttons - Simply-Buttons v2
Viewed 998 times since Thu, Nov 12, 2009