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.

QUANTIFYING THE CHARACTERS

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.

LOGICAL OPERATORS [OR(|) & AND(.)]

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.
Comments
There are no comments for this article. Be the first to post a comment.
Name
Email
Security Code Security Code
Related Articles RSS Feed
PHP Quiz Questions and Answers
Viewed 4791 times since Mon, Jan 11, 2010
PHP Script For PDF to HTML Conversion
Viewed 7661 times since Tue, Dec 15, 2009
Create Glowing, Radioactive Buttons with CSS
Viewed 1344 times since Sun, Dec 27, 2009
Advanced Backup System - PHP Backup Script
Viewed 1469 times since Wed, Jul 28, 2010
Axiis - Open Source Data Visualization Framework
Viewed 1602 times since Thu, Jan 7, 2010
What is new in HTML 5?
Viewed 1362 times since Sat, Apr 3, 2010
How to prevent access to a specific file on server using htaccess?
Viewed 1356 times since Sun, Mar 14, 2010
Embeddable Google Document Viewer For Websites
Viewed 1263 times since Fri, Mar 11, 2011
Create Interactive JavaScript Charts With Highcharts
Viewed 1543 times since Fri, Dec 4, 2009
MENU