5 Regular Expressions that every web developer should know

The hardest part is taking in the linguistic structure and figuring out how to compose your own particular regex code sans preparation. To spare time, I have chosen 30 distinctive regex code pieces that you can use in your tasks. Furthermore, since regex is not constrained to a particular language, you can apply the accompanying sections in any technology from Javascript to PHP or Python.

1 Find a valid Base64 string in PHP
<code class="hljs language-JavaScript">\?php[ \t]eval\(base64_decode\(\'(([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?){1}\'\)\)\;</code>
In case you're a PHP engineer, at that point here and there you can break down through the code to discover objects Base64 encoded double (eg looking shell covered up in a PHP). This regex fragments can apply to all PHP code and will look at any of the current Base64 string.

2 Get Domain Name from URL
<code class="hljs language-JavaScript">/https?:\/\/(?:[-\w]+\.)?([-\w]+)\.\w+(?:\.\w+)?\/?.*/i</code>
Every domain name contains the site in the convention (HTTP or HTTPS) and once in a while the way, subdomain with extra pages. You can utilize this regex portions to slice through the greater part of that and simply return the space name.

3 The Strength of Password
<code class="hljs language-JavaScript">^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&amp;*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$</code>
If you want to implement your own password strength generator you can start with it. This regex is a great starting point if you don’t want to write your own password strength checker from scratch.

4 Authenticate E-mail Address
<code class="hljs language-JavaScript">/[A-Z0<span class="hljs-number">-9.</span>_%+-]+@[A-Z0<span class="hljs-number">-9</span>-]+.+.[A-Z]{<span class="hljs-number">2</span>,<span class="hljs-number">4</span>}/igm</code>
One of the most common task for almost every developer is to check wether a input string from user is valid or not. For PHP,you can use the function filter_var:filter_var($ email,filter_validate_email)

5 Thousand seperator
<code class="hljs language-JavaScript">/\d{<span class="hljs-number">1</span>,<span class="hljs-number">3</span>}(?=(\d{<span class="hljs-number">3</span>})+(?!\d))/g</code>
This Regex code work on any of the numeric string & will apply any delimiter for each 3 digits seperated by thousand ,lacs,million...
This type of Regex is widely used in e-commerce , bidding websites.

Thank you!!
All the best!!

Comments

Popular posts from this blog

Login into Gmail Account Using Web Driver

Tutorial 4

Case study of Library Management System