• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Featured
    • C# Tutorials
      • LinQ Tutorials
      • Facebook C# API Tutorials
    • PHP Tutorials
      • CodeIgniter Tutorials
    • Amazon AWS Tutorials
  • Categories
    • Programming
    • Development
    • Database
    • Web Server
    • Source Control
    • Management
    • Project
  • About
  • Write
  • Contact

CodeSamplez.com

Programming, Web development, Cloud Technologies

You are here: Home / Programming / Get Started With Regular Expression Basics

Get Started With Regular Expression Basics

January 3, 2011 by Rana Ahsan 2 Comments

Programming

This article is intended to those programmers who are very new at regular expression programming. If you know about regular expression basics very well, you may skip this tutorial. But, its always good to give an overview so that you may get something helpful. I have tried to give some easy to understand concept about regular expression programming on what it is, where its used, real world examples and symbol definitions those are used while programming with regular expression. I won’t give any code examples here in any programming language, please keep an eye on following posts of this site to get language specific directions/examples on using regular expression.

What is Regular Expression:

Regular expression, is a representation of a particular characters pattern, or can be defined as an expression that describes a set of strings. Regular expression is also often referred in short as ‘regex’ or ‘regexp’. Its well known in most of the programming languages and every programming language has their own integrated regular expression engine.

Regular Expression Usage:

Regular Expression can be useful in various cases such as:

  • Matches a string of texts against a particular pattern
  • Find occurrence of a specific pattern in a long string texts
  • Replaces a sub string of a specific pattern in a long text string with some other texts
  • Splits a long string into a set of sub strings

Regular Expression In Real Worlds:

In real world programming, there are some common places where regular expressions are used such as:

  • Email Validation. This can be from a list of email adress from file/db or from user input from win/web form.
  • Phone Number Validation (check your mobile plans to make sure everything is okay with your line)
  • URI/Domain validation for http,ftp etc address.
  • Extract specific deli metered text in Data scraping.
  • In .htaccess programming for creating rewrite rule for dynamic urls.

Regular Expression symbols:

There are some special symbols used in constructing a regular expression pattern string. Here are some examples:

  • ^ – Represents the entry point for a pattern. In other words, string to be matched will must need to be begin with character(s) following ‘^’ character. Example, “^http” this pattern will match anything starting with ‘http’.
  • $ – Represents the terminating/ending point for a pattern. In other words, string to be matched will must need to be end with character(s) before ‘$’ character. Such as, ‘\.com$’ will match any string ending with ‘.com’.
  • \w – Represents existence of any word characters
  • \d – Represents existence of any digit characters
  • {n,} – Represents existence of the preceding character(s)/pattern minimum n times.Example, “[\d]{2,}” will match for minimum 2 sequential digits.
  • /i – To treat upper lowe/upper case characters in the same way. Used at the end of the pattern
  • /m – enables multi-line mode.
  • * – Represents existence of any character(s).
  • ? – Represents o or more times existence of preceding character(s).
  • + – Represents 1 or more times existence of preceding character(s).
  • | – Accepts if either side pattern/character(s) matches.

References:

Here I tried to provide the basic concepts, usage and syntax for beginning a better and quick start with regular expression basics programming. After having the basic idea, you will might want to go some for more advance level studies. Wiki Article on Regular Expression have some good discussions with several references also. Also regular-expression.info is a dedicated site for discussions,tutorials on regular expression. Hope this will be helpful for you. Happy coding :).

Share If Liked

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)

You may also like

Filed Under: Programming Tagged With: regular expression

About Rana Ahsan

Rana is a passionate software engineer/Technology Enthusiast.
Github: ranacseruet

Reader Interactions

Trackbacks

  1. C# Tutorial For Regular Expression In .NET | codesamplez.com says:
    January 5, 2011 at 1:42 am

    […] is regular expression in programming again as I already mentioned about its concept on my earlier regular expression basics post.Here I am going to discuss about its practical implementation with c# language. Almost all […]

    Reply
  2. PHP Regular Expression Programming Tutorial | codesamplez.com says:
    January 9, 2011 at 12:47 pm

    […] language. If you are comparatively new at regular expression programming, you can refer to regular expression basics, what i have discussed earlier on this blog, for a better […]

    Reply

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Follow Us

  • Twitter
  • Facebook

Top Posts & Pages

  • PHP HTML5 Video Streaming Tutorial
    PHP HTML5 Video Streaming Tutorial
  • How To Work With JSON In Node.js / JavaScript
    How To Work With JSON In Node.js / JavaScript
  • Generate HTTP Requests using c#
    Generate HTTP Requests using c#
  • LinQ Query With Like Operator
    LinQ Query With Like Operator
  • How To Work With C# Serial Port Communication
    How To Work With C# Serial Port Communication
  • Using Supervisord Web Interface And Plugin
    Using Supervisord Web Interface And Plugin
  • Getting Started With Smarty Template Engine
    Getting Started With Smarty Template Engine
  • How To Work With Codeigniter Caching In PHP
    How To Work With Codeigniter Caching In PHP
  • LinQ To SQL Database Update Operations In C#
    LinQ To SQL Database Update Operations In C#
  • PHP CodeIgniter Tutorials For Developers
    PHP CodeIgniter Tutorials For Developers

Recent Posts

  • Building Auth With JWT – Part 2
  • Building Auth With JWT – Part 1
  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read

Tags

.net angularjs apache api audio auth authenticatin aws c# cloud server codeigniter deployment docker doctrine facebook git github golang htaccess html5 http javascript jwt linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty socket.io tfs tips unit-test utility web application wordpress wpf

Footer

Archives

Follow Us

  • Twitter
  • Facebook

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Copyright © 2023