<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sohan Lal Gupta on Medium]]></title>
        <description><![CDATA[Stories by Sohan Lal Gupta on Medium]]></description>
        <link>https://medium.com/@slgupta022?source=rss-1c4a8a3620d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1CHUCD9iIayUyOZRpj6xkQ.jpeg</url>
            <title>Stories by Sohan Lal Gupta on Medium</title>
            <link>https://medium.com/@slgupta022?source=rss-1c4a8a3620d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:28:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@slgupta022/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Regular Expression in Python]]></title>
            <link>https://medium.com/analytics-vidhya/regular-expression-in-python-5ab2e8b707f1?source=rss-1c4a8a3620d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ab2e8b707f1</guid>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[python-regex]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sohan Lal Gupta]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 17:35:31 GMT</pubDate>
            <atom:updated>2021-02-07T16:31:19.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*RTHEp73YHwMnUFZ_26xm9w.jpeg" /><figcaption><a href="https://tutorial.eyehunts.com/python/python-regex-regular-expression-re-example/">https://tutorial.eyehunts.com/python/python-regex-regular-expression-re-example</a></figcaption></figure><p>Regular Expression is also called RE or RegEx, in short. It is a sequence of characters that forms a search pattern. It is used to check whether the search pattern exists in the given string. At first glance, It may seem complicated due to weird symbols like ^$.*+- etc. But, It’s a powerful tool that is worth learning. At the end of the article, We will see some useful regex examples of real-world applications.</p><h3>Python Module (re)</h3><p>Python has a module named <strong>re, </strong>which lets you deal with the regular expressions. Many regex functionalities are residing in the module.</p><pre>import re</pre><p>Let us see some important functionalities of the re module.</p><h4>re.findall()</h4><p>It returns a list of all matching patterns.</p><pre>re.findall(pattern, string)</pre><p><em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3ff40ae6acd9639af0faa5c86644b53/href">https://medium.com/media/e3ff40ae6acd9639af0faa5c86644b53/href</a></iframe><h4>re.search()</h4><p>It returns a match object of the first location of the pattern in the string.</p><pre>re.search(pattern, string)</pre><p><em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ba956a5bd5aaef2c7085a7b1b365bcc/href">https://medium.com/media/0ba956a5bd5aaef2c7085a7b1b365bcc/href</a></iframe><h4>re.split()</h4><p>It returns a list where the string has been split at each match.</p><pre>re.split(pattern, string)</pre><p><em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f34b7f5c9a3b72cbbd5fa18ff415484f/href">https://medium.com/media/f34b7f5c9a3b72cbbd5fa18ff415484f/href</a></iframe><h4>re.sub()</h4><p>It replaces one or many matches with a string.</p><pre>re.sub(pattern, replace, string, count=0)</pre><p>Here, the default value of count is equal to zero means it will replace all the matching patterns in the string. If we pass the value of count other than zero, then that would be the number of the matching patterns in the string.</p><p><em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14affa0914195e3eda69ae9b0e3eba7a/href">https://medium.com/media/14affa0914195e3eda69ae9b0e3eba7a/href</a></iframe><p><em>Another example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/404df5f40da07d7f6d768a11f5661076/href">https://medium.com/media/404df5f40da07d7f6d768a11f5661076/href</a></iframe><p>Now, We will see special characters and special sequences. By using these, You can define your own regex.</p><h3>Special Characters</h3><p>I have created a table of special characters. After that, we will see all these special characters in detail.</p><pre><strong>^ :</strong> Matches the start of the string</pre><pre><strong>$ :</strong> Matches the end of the string</pre><pre><strong>. :</strong> Matches any character except a newline</pre><pre><strong>? :</strong> Repeats a character zero or one time</pre><pre><strong>+ :</strong> Matches one or more repetitions of the preceding RE</pre><pre><strong>+? :</strong> Matches one or more repetitions of the preceding RE(non-greedy)</pre><pre><strong>* :</strong> Matches zero or more repetitions of the preceding RE</pre><pre><strong>*? :</strong> Matches zero or more repetitions of the preceding RE(non-greedy)</pre><pre><strong>\ :</strong> Signals a special sequence</pre><pre><strong>| :</strong> Used for alternation</pre><pre><strong>[] :</strong> Used to indicate a set of characters</pre><pre><strong>() :</strong> Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group</pre><pre><strong>{m} :</strong> Specifies that exactly <em>m</em> copies of the previous RE should be matched</pre><pre><strong>{m,n} :</strong> Matches from <em>m</em> to <em>n</em> repetitions of the preceding RE, attempting to match as many repetitions as possible</pre><h4><strong>^ (Caret)</strong></h4><p>It matches the start of the string. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2187975825a425867680bbc2a65ae295/href">https://medium.com/media/2187975825a425867680bbc2a65ae295/href</a></iframe><h4>$ (Dollar)</h4><p>It matches the end of the string.<em> For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/089b4bfbb4e9ef021c3b3785c1e73758/href">https://medium.com/media/089b4bfbb4e9ef021c3b3785c1e73758/href</a></iframe><h4>. (Dot)</h4><p>It matches any character except a newline. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33335d7b925a56a6973817bdd9ce0838/href">https://medium.com/media/33335d7b925a56a6973817bdd9ce0838/href</a></iframe><h4>? (Question Mark)</h4><p>It matches zero or one repetition of the preceding RE. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15dbc5918e522789b6a7c340316a388e/href">https://medium.com/media/15dbc5918e522789b6a7c340316a388e/href</a></iframe><p>In the above example, <em>‘a’</em> has zero repetition in the string. Let us see another example where <em>‘a’</em> will match with one repetition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66ef49e341e5a4a40d8846591d326847/href">https://medium.com/media/66ef49e341e5a4a40d8846591d326847/href</a></iframe><p>What will happen if there is more than one ‘a’ in the string (e.g. ‘maan’). Let us see one more example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc3139ea89ae818027e48f2af0ea1f2c/href">https://medium.com/media/bc3139ea89ae818027e48f2af0ea1f2c/href</a></iframe><p>You saw in the above example that It would not match if the repetition is more than one.</p><h4>+ (Plus)</h4><p>It matches one or more repetitions of the preceding RE. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f98834573578483283bed1a85f31792a/href">https://medium.com/media/f98834573578483283bed1a85f31792a/href</a></iframe><p><em>Another example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b2a3d83ddd09941e0d6a261d085b29a/href">https://medium.com/media/9b2a3d83ddd09941e0d6a261d085b29a/href</a></iframe><p>In the above example, ‘^F’ means string starts with ‘F’ and ‘.+’ means matches any character any number of times( ≥1) till the character ‘:’ (i.e., there is at least one character between ‘F’ and ‘:’).</p><p>Since ‘+’ is a greedy means, it matches as much string (or text) as possible. So, it doesn’t stop scanning at first ‘:’. It scans till the end of the string. Thus, the output is <em>[‘From : using the :’]</em>.</p><h4>+?</h4><p>It matches one or more repetitions of the preceding RE (non-greedy). Non-greedy means it matches as little string (or text) as possible. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/679d8e7bde700be01aced4f9a16b4f41/href">https://medium.com/media/679d8e7bde700be01aced4f9a16b4f41/href</a></iframe><p>In the above example, It scans till the first ‘:’ due to the non-greedy behavior of +?.</p><h4>* (Star)</h4><p>It matches zero or more repetitions of the preceding RE. It is also greedy. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25de5ed8d03a80523956b39ba0f247b5/href">https://medium.com/media/25de5ed8d03a80523956b39ba0f247b5/href</a></iframe><p>The above example is same as the + example which you have already seen. Then, What is the difference between + and * ? Let us see another example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e66b61e7c38c448389cb42d0b03569c3/href">https://medium.com/media/e66b61e7c38c448389cb42d0b03569c3/href</a></iframe><p>In the above example, the pattern also matched with ‘Heo’. ‘l*’ means zero or more times ‘l’. In the above example, the number of ‘l’ is zero. That’s why it matched, but if I write ‘+’ instead of ‘*’ in the pattern then at least one ‘l’ should be there in the string.</p><p><em>Another example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4319802090c467ee444895929be9ad8d/href">https://medium.com/media/4319802090c467ee444895929be9ad8d/href</a></iframe><h4>*?</h4><p>It matches zero or more repetitions of the preceding RE (non-greedy). <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f6efd19d095d8d2d11ad6076c6ca1e4/href">https://medium.com/media/1f6efd19d095d8d2d11ad6076c6ca1e4/href</a></iframe><p>It is non-greedy. So, it matches as little as possible(i.e., zero repetition). Thus, the output is <em>[‘He’]</em>.</p><h4>\ (Backslash)</h4><p>It signals a special sequence. We will see this topic in detail in Special Sequences .</p><h4>| (Alternation)</h4><p>It is used for alternation. Like A|B, where A and B can be arbitrary REs, it will match any string that contains either A or B. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a49a8794824d3115c565366bc73da6b/href">https://medium.com/media/2a49a8794824d3115c565366bc73da6b/href</a></iframe><h4>[] (Square Brackets)</h4><p>It is used to indicate a set of characters. Like,</p><pre><strong>[aeiou] :</strong> Matches a single character in the listed set</pre><pre><strong>[^xyz] :</strong> Matches a single character not in the listed set</pre><pre><strong>[a-z0-9] :</strong> Matches a single character between a to z or 0 to 9.</pre><p><em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1304bed5d1859de81ec412a68db66d6b/href">https://medium.com/media/1304bed5d1859de81ec412a68db66d6b/href</a></iframe><p><em>Another example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4465371b629069b4c5a87995137c8b9e/href">https://medium.com/media/4465371b629069b4c5a87995137c8b9e/href</a></iframe><p><em>One more example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9710a0281ad22e7a25215fbdebfa068b/href">https://medium.com/media/9710a0281ad22e7a25215fbdebfa068b/href</a></iframe><h4>() (Parentheses)</h4><p>It matches whatever regular expression is inside the parentheses and indicates the start and end of a group. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07ec0bd093d31bc3957394382f940922/href">https://medium.com/media/07ec0bd093d31bc3957394382f940922/href</a></iframe><p>In the above example, It matches the string starts with ‘From ’ and after that matches any character any number of times till ‘@’ and then matches any character except space(‘ ’) according to RE written inside parentheses. It returns only the characters that would match according to RE inside the parentheses.</p><h4>{m}</h4><p>It specifies that exactly <em>m</em> copies of the previous RE should be matched. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a273dd79a057755345569e8c12e1781/href">https://medium.com/media/6a273dd79a057755345569e8c12e1781/href</a></iframe><p>In the above example, ‘i{3}’ means three times ‘i’. So, the output is <em>[‘Mississippiii’].</em></p><h4>{m,n}</h4><p>It matches from <em>m</em> to <em>n</em> repetitions of the preceding RE, attempting to match as many repetitions as possible. <em>For example:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8e8dbd0203969dc6dc34a49aee0a193/href">https://medium.com/media/c8e8dbd0203969dc6dc34a49aee0a193/href</a></iframe><h3>Special Sequences</h3><pre><strong>\s :</strong> Matches any whitespace character (i.e. equivalent to the class [ \t\n\r\f\v])</pre><pre><strong>\S :</strong> Matches any non-whitespace character (i.e. equivalent to the class [^ \t\n\r\f\v])</pre><pre><strong>\d :</strong> Matches any decimal digit (i.e. equivalent to the class [0-9])</pre><pre><strong>\D :</strong> Matches any non-digit character (i.e. equivalent to the class      [^0-9])</pre><pre><strong>\w :</strong> Matches any alphanumeric character (i.e. equivalent to the class [a-zA-Z0-9_])</pre><pre><strong>\W :</strong> Matches any non-alphanumeric character (i.e. equivalent to the class [^a-zA-Z0-9_])</pre><p><em>Examples:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e9babf05e5b70b04c5aabc864db8665/href">https://medium.com/media/3e9babf05e5b70b04c5aabc864db8665/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0781a27415c579785bcdde80132a188/href">https://medium.com/media/b0781a27415c579785bcdde80132a188/href</a></iframe><p>Some useful regex examples of real-world applications:</p><p><strong>Example 1: Extracting date from string</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0a2ba79525fc422fb2f0343c24f081/href">https://medium.com/media/6a0a2ba79525fc422fb2f0343c24f081/href</a></iframe><p><strong>Example 2: Check Email is valid or not</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d317ee906c75335db47ee1d5b4ebb169/href">https://medium.com/media/d317ee906c75335db47ee1d5b4ebb169/href</a></iframe><p><strong>Example 3: Check URL is valid or not</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c7a3167f9a8b2b2bbaa45a630c384bc/href">https://medium.com/media/4c7a3167f9a8b2b2bbaa45a630c384bc/href</a></iframe><h3>Summary</h3><p>Regex is used to check whether the search pattern exists in the given string. In Python, there is an inbuilt library named re which deals with regular expression. I think I have covered most of the concepts with suitable examples.</p><p>If you have any questions or suggestions, feel free to leave them in the comments below.</p><p>Thanks for reading and have fun learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ab2e8b707f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/regular-expression-in-python-5ab2e8b707f1">Regular Expression in Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Email Verification using SendGrid in Node.js, Express.js & MongoDB]]></title>
            <link>https://slgupta022.medium.com/email-verification-using-sendgrid-in-node-js-express-js-mongodb-c5803f643e09?source=rss-1c4a8a3620d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5803f643e09</guid>
            <category><![CDATA[sendgrid]]></category>
            <category><![CDATA[email-verification]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sohan Lal Gupta]]></dc:creator>
            <pubDate>Sat, 22 Aug 2020 10:05:07 GMT</pubDate>
            <atom:updated>2021-07-18T06:10:49.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aKMdzC6raaW6T_Fn" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Web Applications usually need users to register with a working email. A working email helps in account management. So, Email verification is important for ensuring a valid email. Here, we’ll implement verification of email by sending a token/link to activate an account. We’ll also implement resend token/link.</p><h4>Install Node Modules</h4><pre>npm install bcryptjs --save<br>npm install crypto --save<br>npm install nodemailer --save<br>npm install nodemailer-sendgrid-transport --save</pre><h4>Import above Modules</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5999c8bf96100cb36dd9fd9528f3997/href">https://medium.com/media/c5999c8bf96100cb36dd9fd9528f3997/href</a></iframe><h4>Create account on SendGrid and required things for sending email</h4><p>We have to do three things, steps are given below:</p><ol><li>Go to this link: <a href="https://sendgrid.com/">https://sendgrid.com/</a> and create your account.</li><li>After creating your account on SendGrid, Go to Settings -&gt; Sender Authentication -&gt; click on the Verify a Single Sender button under Single Sender Authentication section. If Verify a Single Sender button is not there, then Go to Dashboard from the left side navigation, You will surely see that button on the dashboard. Fill the required details and click on the create button. You will receive an email, verify your email address.</li><li>Again Go to Settings -&gt; API Keys -&gt; create API Key . Fill the API name and click on Create &amp; View button. Your API Key has been generated, copy that Key.</li></ol><h4>User Model</h4><p>User Schema has four fields name, email, isVerified and password. Here, isVerified is the boolean type. If the user’s account is not verified then isVerified is false. otherwise true.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/259b5f8f0a4c65bf8f47419e015e8e58/href">https://medium.com/media/259b5f8f0a4c65bf8f47419e015e8e58/href</a></iframe><h4>Token Model</h4><p>Token Schema has three fields _userId, token and expireAt. _userId is referenced to the User. token is a type of string that is randomly generated during signup. Here, we default set the expiry of token is 86400000 ms (24hrs). You can change it as your need.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81511912bbe524dd311f30b376194c11/href">https://medium.com/media/81511912bbe524dd311f30b376194c11/href</a></iframe><h4>Log In</h4><p>Here, we check the user’s account is verified or not. If the user’s account is verified then login successful otherwise we sent unauthorized (401) status code with a suitable message.</p><p>The given code is the POST method of login.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0df5a432ff5d25a62b9be2db0abc8e4/href">https://medium.com/media/b0df5a432ff5d25a62b9be2db0abc8e4/href</a></iframe><h4>Sign Up</h4><p>Users need to sign up before login. Users must have a verified account for login. Here, we’ll register the user’s account and send an email to verify that account. Users would have to click on the account verification link before the link expires. After that user’s account gets verified.</p><p>In the below code, You have to write the API key which is generated on SendGrid (in step 3). And in the from field a sender&#39;s email will be required which you have already verified on SendGrid (in step 2).</p><p>The given code is the POST method of sign up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d06f03b2c906c36cd666654b23196701/href">https://medium.com/media/d06f03b2c906c36cd666654b23196701/href</a></iframe><h4>Verify Account</h4><p>Here, we’ll verify the user’s account when the user clicks on the account verification link sent to their email.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a4c705a0cb5d43728a0937ab60be736/href">https://medium.com/media/4a4c705a0cb5d43728a0937ab60be736/href</a></iframe><h4>Resend Token/Link</h4><p>If the account verification link has been expired or not sent (due to some technical issue) then users will click on the resend link and again get an account verification link.</p><p>The given code is POST method of resendLink.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25e7f0b6ef974a1378f708b83fd53a7d/href">https://medium.com/media/25e7f0b6ef974a1378f708b83fd53a7d/href</a></iframe><h4>Conclusion</h4><p>I hope this will help you with Email verification using Sendgrid.</p><p>If you have any questions or suggestions, feel free to leave them in the comments below.</p><p>Thanks for reading and have fun learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5803f643e09" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>