Having powerful and regular tools in the hands of a developer is a good thing. They can help you match against of the most complex characters parameters. That can save you from so much time you waste building websites that look them dynamic.

It has been seen that web developers face so many tasks instead software developers, but in some point the fundamentals of codes remain the same. Regular REGEX certainly has the initial steep of learning, but also they can be an amazing powerful when you decide them to use correctly.

The most trickiest and difficult part of its learning is that how you can write your REGEX codes with scratch. To save your precious time we have listed best 30 REGEX snippets code that all the web developers have to know about them, Which you can use in your projects that you are developing and since it is not a limited to one language, you can also apply using snippets on PHP, JavaScript and python as well.

REGEX snippets code

1) Strength of the password


Checking the strength of a password is a subjective which is not an absolute right answer. But this snippet REGEX is the great way to write the point in your own strength of password checker.


2) Use hex-decimal method color

Everywhere you go, you will find the field of web development presence. Using the hex codes with snippet REGEX can be pull to match the sting of any purposes.

\#([a-fA-F]|[0-9]){3, 6}

3) Checking the validity of E-mail addresses

One common task that a developer needs to check it the string of the style of the E-mail addresses. Different varieties can be accomplished in it, so this point out that tow codes of snippets is enough to check E-mail syntax.


4) IP-v4 addresses

It is similar to the E-mail address, an IP address is used to verify to computer access with internet. Using the regular REGEX will used to see how the string follows its IP-v4 syntax address.


5) IP-v6 addresses

You probably want to check the new address of the IP-v6 using advanced snippet REGEX. A very minor difference it has due to the development process.


6) thousand Of separators

Numbering of traditional system needs a period or a mark in every digit with large number. REGEX is used on many numbers to apply the mark you have chosen from the thousand or million digits separating.


7) Prepare the hyperlink to HTTP

If you are working on PHP, ruby, or JavaScript with regular REGEX can be very useful. It will check the URL syntax to fin it has HTTPS or HTTP prefix and prepare it.

if (!s.match(/^[a-zA-Z]+:\/\//))
    s = 'http://' + s;

8) Pulling the domain using URL

The domains of each website contain the beginning protocol of HTTPS, plus with some additional path of pages as well. Use snippet and cut all and just write name of domain.


9) Sort keywords category with word count

People who use webmaster tools or Google analytics can really enjoy the regular REGEX. You can make the categories of keywords which are based on the number of the words.

^[^\s]*$        matches exactly 1-word keyword
^[^\s]*\s[^\s]*$    matches exactly 2-word keyword
^[^\s]*\s[^\s]*     matches keywords of at least 2 words (2 and more)
^([^\s]*\s){2}[^\s]*$    matches exactly 3-word keyword
^([^\s]*\s){4}[^\s]*$    matches 5-words-and-more keywords (longtail)

10) Search valid-base PHP string

PHP developer in some point will find the codes that is based on 64 encoded, the snippet you can use in all the PHP codes and search the base of its strings.

\?php[ \t]eval\(base64_decode\(\'(([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?){1}\'\)\)\;

11) Use right number of the phone

The code of the REGEX will use right traditional number of the phone syntax that is based on the American style. It is a fair subject to find more detail answers.

^\+?\d{1,3}?[- .]?\(?(?:\d{2,3})\)?[- .]?\d\d\d[- .]?\d\d\d\d$

12) Trailing and leading the white-space

Try using snippet code to trail and lead the white-space with string. It is not a big deal, but it can affect the output of the database with other encoding of documents.

^[ \s]+|[ \s]+$

13) Puling the source of image

If you need to pull the source of image out using HTML, then snippet EGEX code is best for this solution. It also runs very smoothly as well.

\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)

14) Validate Date in the format of MM/DD/YYYY

Date can be very difficult to create because you need number and texts to make them in different fonts and PHP has the perfect function of date setting. When you are pulling the string of raw use regular REGEX with the right syntax of date.


15) ID match of the YouTube video

YouTube has same URL for many years because it is very famous video sharing website and the great source to drive more traffic as well.


16) Point out the ISBN

Books that are printed in number system are called ISBN. Sometimes it can be very difficult to tell the difference in them. The snippet will help you point out the ISBN and codes will be in PHP that can be very helpful for you.

/\b(?:ISBN(?:: ?| ))?((?:97[89])?\d{9}[\dx])\b/i

17) Zip code checking

This snippet work is totally free the developer has explained that you will find this very helpful in so many ways, with typical 6 digit coding zip to the 9 version digit.


18) How to validate a Twitter username using Regex

The smallest REGEX code to match the username of twitter in string, it automatically check and scan the contents about tweets.


19) Number of credit cards

Creating the number of credit card needs a platform that is secure online. But you can use snippet REGEX code to complete the minimal needs of the number of credit cards.


20) Finding the attributes of CSS

It will be special to run REGEX codes on CSS, but it seems that it is a very odd condition. It used to pull out the matching CSS value and its property individually. It uses to removing the same properties of the duplicates.


21) Comments of strip HTML

If you need to remove all the comments from blocking the HTML, Then this snippet REGEX is very great for you. It can also replace the PHP expression as well.


22) URL of facebook profile

This site has gone into many schemes of URL. In a condition which you taking your profile using strings and confirm its structure easily. This REGEX code can do the same with the perfect face book link.


23) Internet explorer version checking

Microsoft’s moving to edge browser is a very arguably thing. But people still prefers to use the internet explorer. Some developers need to check the IE version of it with render engine.

^.*MSIE [5-8](?:\.[0-9]+)?(?!.*Trident\/[5-9]\.0).*$

24) How to Extract Price

Price comes with several great formats which contains currency and commas symbols. This regular REGEX can surely check the different prices to cut the price with strings.


25) Analyze the header of e-mail

This one line code can help to analyze the header of the e-mail to get the information from it. You can use it with other multiple joined email tandem also.


26) Particularly match the file-type

When you working in different files such as, HTML, XML and JavaScript to check the local user’s files, then the extension of its valid series can be changed in so many ways.


27) URL matching string

The REGEX can use the HTTP or strings to check the text with traditional domain. The simple implementation of the snippet is great to match URL with string.


28) Attach the links to no-follow

Working on the HTML code can apply numerous labor using repetitive options. Regular REGEX is best for this time and will save you a lot time in the process.

(<a\s*(?!.*\brel=)[^>]*)(href="https?://)((?!(?:(?:www\.)?'.implode('|(?:www\.)?', $follow_list).'))[^"]+)"((?!.*\brel=)[^>]*)(?:[^>]*)>

29) Media queries matching

Break the CSS some media query to match its parameters with accessing. It can help you analyzing the clear CSS with focus on direct code operations.

[email protected]([^{]+)\{([\s\S]+?})\s*}/g

30) Searching Google syntax

Create your own snippet code with searchable text using the Google search trademark. A plus sign can donate the keywords and should remove the ignored results.

/([+-]?(?:'.+?'|".+?"|[^+\- ]{1}[^ ]*))/g