<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jobsity</title>
    <description>The latest articles on DEV Community by Jobsity (@jobsity).</description>
    <link>https://dev.to/jobsity</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F800170%2F3b78f30d-b2f9-4f64-8cf3-e9098145bfe1.jpg</url>
      <title>DEV Community: Jobsity</title>
      <link>https://dev.to/jobsity</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jobsity"/>
    <language>en</language>
    <item>
      <title>Getting Started with Background Tasks In ASP.NET Core WebAPI</title>
      <dc:creator>Jobsity</dc:creator>
      <pubDate>Wed, 30 Mar 2022 22:34:18 +0000</pubDate>
      <link>https://dev.to/jobsity/getting-started-with-background-tasks-in-aspnet-core-webapi-15n0</link>
      <guid>https://dev.to/jobsity/getting-started-with-background-tasks-in-aspnet-core-webapi-15n0</guid>
      <description>&lt;p&gt;If you are building a web application, you may have encountered scenarios where some operation needs to be performed indefinitely. So how to handle such scenarios? An efficient way to tackle such scenarios is by using background services. In this tutorial, we will be learning how to create background services in the .NET Core web applications. The .NET Core is Microsoft's offering for building cross-platform applications and now its gaining popularity more than ever. &lt;/p&gt;

&lt;p&gt;But first, let's understand more about background services below:&lt;/p&gt;

&lt;h2&gt;
  
  
  A Short Introduction to Background Services
&lt;/h2&gt;

&lt;p&gt;First, let us discuss why do we need background tasks. In any application, there is a main thread that is responsible for the execution of the application. This thread accepts the requests, performs logic, and finally returns the output.&lt;/p&gt;

&lt;p&gt;But there are scenarios where you don't want to delegate your jobs to this main thread. For instance:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You have to process images or manipulation of media. Image processing and image manipulation, for instance, is a resource extensive task; hence it is more suited for background operation. &lt;/li&gt;
&lt;li&gt;You might want to schedule some jobs for some specific time of day or at any particular time of day. For example, you might need to send the emails to your subscribers at midnight. Background jobs offer a perfect solution for this.&lt;/li&gt;
&lt;li&gt;You have to continuously listen for some event. This event can be either internal or external. For example, you might have an application that reacts to the change in the forex rates. So this process runs throughout the lifetime of the application. Hence we can initiate this process in the background and let it listen. &lt;/li&gt;
&lt;li&gt;You have to perform IO operations that are extensive such as reading the disk for files. Reading lengthy files, which can be from gigabytes to terabytes, if we perform this operation on the main thread, it will freeze the application resulting in a downgraded user experience. Hence having background service taking care of this extensive task provides a smoother user experience.&lt;/li&gt;
&lt;li&gt;You want to periodically perform house keeping operations such as database cleaning, update secondary database or garbage collections operations.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Options Available
&lt;/h2&gt;

&lt;p&gt;Now that you are equipped about the background tasks, let's look at the options available to you to build them. The .NET Core offers three classes to assist you with it: IHostedService and BackgroundService. &lt;/p&gt;

&lt;p&gt;Other options are not offered by .NET Core, rather third party offerings. You can use the Hangfire library or opt for some cloud based solution. &lt;/p&gt;

&lt;p&gt;Here in this tutorial, we will stick to the solutions provided by the .NET Core.&lt;/p&gt;

&lt;p&gt;We will be creating a service that continuously prints out time after every second until the application shuts down.&lt;/p&gt;

&lt;h3&gt;
  
  
  IHostedService
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;IHostedService&lt;/code&gt; is an interface that provides the base for implementing the background services or tasks. For any class to operate as a background service, it must implement this interface. Once implemented, the implementing class has to override two methods: &lt;code&gt;StartAsync(CancellationToken)&lt;/code&gt; and &lt;code&gt;StopAsync(CancellationToken)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, this hosted service must be registered in the application during the startup of the application. You can register the hosted service in the application by calling the method: &lt;code&gt;AddHostedService&amp;lt;Your_Class&amp;gt;()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's create our service using &lt;code&gt;IHostedService&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;For the sake of simplicity, I am using the ASP.NET Core WebAPI project. You can create a new project in Visual Studio to get started. &lt;/p&gt;

&lt;p&gt;Now within this project, create a new file called &lt;code&gt;ImplementIHostedService.cs&lt;/code&gt;. This class is basically our service and it implements the &lt;code&gt;IHostedService&lt;/code&gt; interface. Add the below code in this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace WebApplication3.Services
{
    public class ImplementIHostedService : IHostedService
    {
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Task.Run(async () =&amp;gt;
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    Console.WriteLine($"Respponse from IHostedService - {DateTime.Now}");
                    await Task.Delay(1000);
                }
            });

            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("Shutting down IHostedService");
            return Task.CompletedTask;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you will need to register this service in the service registration. Open the &lt;code&gt;Startup.cs&lt;/code&gt; file and add the below line in the &lt;code&gt;ConfigureServices&lt;/code&gt; method:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;services.AddHostedService&amp;lt;ImplementIHostedService&amp;gt;();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now run the project and you will see the console returning back the output after one-second delay. If you close the application you will see the output &lt;code&gt;Shutting down IHostedService&lt;/code&gt; message.&lt;/p&gt;

&lt;p&gt;To summarize:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First we create the class that represents our background service. &lt;/li&gt;
&lt;li&gt;Next, we implement the &lt;code&gt;IHostedService&lt;/code&gt; in this class.&lt;/li&gt;
&lt;li&gt;You will need to override two critical methods in your class: &lt;code&gt;StartAsync&lt;/code&gt; and &lt;code&gt;StopAsync&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;StartAsync&lt;/code&gt;, we fire a new task that performs the background job for us. This task runs in the background and perform the long running operation.&lt;/li&gt;
&lt;li&gt;Finally, we override the &lt;code&gt;StopAsync&lt;/code&gt; method. We do this to handle any clean up tasks when the application is shut down.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Let's create our service using &lt;code&gt;BackgroundService&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Here, we will create the same functionality by inheriting &lt;code&gt;BackgroundService&lt;/code&gt;. The &lt;code&gt;BackgroundService&lt;/code&gt; is an &lt;code&gt;abstract&lt;/code&gt; class provided by .NET Core that implements &lt;code&gt;IHostedService&lt;/code&gt; but conceals the mechanics behind it. As we shall see the implementation becomes very clean in &lt;code&gt;BackgrounfService&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In your ASP.NET Core WebApi project, create a new file called &lt;code&gt;ImplementBackgroundService.cs&lt;/code&gt;. Add the below code in this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace WebApplication3.Services
{
    public class ImplementBackgroundService : BackgroundService
    {
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                Console.WriteLine($"Respponse from Background Service - {DateTime.Now}");
                await Task.Delay(1000);
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we do not have to worry about the &lt;code&gt;StartAsync&lt;/code&gt; or &lt;code&gt;StopAsync&lt;/code&gt; methods. Rather, we have a single method called &lt;code&gt;ExecuteAsync&lt;/code&gt;. We override this method to add our functionality. The point to note here is we do not have to create a new &lt;code&gt;Task&lt;/code&gt; when working with &lt;code&gt;BackgroundService&lt;/code&gt;. Rather the service works in the background. &lt;/p&gt;

&lt;p&gt;Finally, we have to register our service in the &lt;code&gt;Startup.cs&lt;/code&gt; file. Add the below line of code in the method &lt;code&gt;ConfigureServices&lt;/code&gt; of the &lt;code&gt;Startup.cs&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;services.AddHostedService&amp;lt;ImplementBackgroundService&amp;gt;();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the application and you will see the similar output here as well. &lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use &lt;code&gt;IHostedService&lt;/code&gt; and &lt;code&gt;BackgroundService&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;IHostedService&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;IHostedService&lt;/code&gt; provides the basic framework for building the background operations. It gives developers the control to begin and end the operations. Having this control allows development of complex scenarios where manual tweaks are needed. Developers opt for this way when they need to build scenarios that are complex and require careful implementation for starting and stopping of the service. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;BackgroundService&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;BackgroundService&lt;/code&gt; abstracts the working of the code and provides a simple way to initiate long-running tasks. For scenarios that are simple and do not require much tweaking, &lt;code&gt;BackgroundService&lt;/code&gt; offers a readily available solution to jump-start the development. Therefore developers prefer it when they just want to get started with the task without having to worry much about the mechanics. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we looked at how we can setup background tasks. These tasks are very helpful in running and processing the information concealed from the user. If properly used, these services can drastically improve the overall experience of the web application and make the processing faster. You can handle long running tasks that require huge computing resources and memory in efficient manner. &lt;br&gt;
                               --&lt;br&gt;
Feel free to browse through the other sections of the blog where you can find many other amazing articles on &lt;a href="https://www.jobsity.com/blog/tutorials" rel="noopener noreferrer"&gt;Programming&lt;/a&gt; and &lt;a href="https://www.jobsity.com/blog/it" rel="noopener noreferrer"&gt;IT&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;And if you are interested in joining our amazing team and working with top U.S. based clients, then &lt;a href="https://recruitment.jobsity.com/applylp" rel="noopener noreferrer"&gt;apply here&lt;/a&gt; and take your career to the next level.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>dotnetcore</category>
      <category>aspnet</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Use Regular Expressions in Python</title>
      <dc:creator>Jobsity</dc:creator>
      <pubDate>Fri, 25 Feb 2022 23:11:25 +0000</pubDate>
      <link>https://dev.to/jobsity/how-to-use-regular-expressions-in-python-3a2d</link>
      <guid>https://dev.to/jobsity/how-to-use-regular-expressions-in-python-3a2d</guid>
      <description>&lt;p&gt;In Python, Regular Expressions are also known as RegEx. RegEx is a unique text string used for defining a search pattern. Regular Expression is beneficial for extracting information from text such as code, files, logs, spreadsheets, or even documents. In simple words, RegEx is a combination of letters, symbols, and numbers you can use to search for things within a longer text.  &lt;/p&gt;

&lt;p&gt;This article sheds light on the usage of Regular Expression using Python. &lt;/p&gt;

&lt;p&gt;While you are using the Regular Expression in Python, the first and foremost thing is to understand that everything is a character, and you are reproducing patterns to match a specific sequence of characters also regarded as strings. &lt;/p&gt;

&lt;p&gt;In the programming world, both newbie and experienced developers often ask how vital learning RegEx is. Today our quest is to find out the importance of RegEx in the context of development with some simple and relevant examples.  &lt;/p&gt;

&lt;p&gt;Let me introduce some fundamental metacharacters in RegEx and their purpose of use. To know more about RegEx syntax, you may check the&lt;a href="https://docs.python.org/3/library/re.html#regular-expression-syntax" rel="noopener noreferrer"&gt; Official Documentation&lt;/a&gt;. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;Character(s)&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
&lt;strong&gt;What it does in Python&lt;/strong&gt; 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;. - &lt;/strong&gt;A period. 
   &lt;/td&gt;
   &lt;td&gt;
Matches up any single character except the newline character. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;^ - &lt;/strong&gt;A caret. 
   &lt;/td&gt;
   &lt;td&gt;
Matches up a pattern at the start of the string. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\A - &lt;/strong&gt;Uppercase A.  
   &lt;/td&gt;
   &lt;td&gt;
It matches up only at the start of the string. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;$ - &lt;/strong&gt;Dollar sign.  
   &lt;/td&gt;
   &lt;td&gt;
Matches the end of the string. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\Z - &lt;/strong&gt;Uppercase Z.  
   &lt;/td&gt;
   &lt;td&gt;
It matches up only at the end of the string. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;[] &lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
It matches the set of characters you specify within it. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\ - &lt;/strong&gt;Backslash.  
   &lt;/td&gt;
   &lt;td&gt;
Used to drop the special meaning of character following it 

&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\w - &lt;/strong&gt;Lowercase w.  
   &lt;/td&gt;
   &lt;td&gt;
It matches any single letter, digit, or underscore. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\W - &lt;/strong&gt;Uppercase W.  
   &lt;/td&gt;
   &lt;td&gt;
Matches any character not part of \w. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\s - &lt;/strong&gt;Lowercase s.  
   &lt;/td&gt;
   &lt;td&gt;
Matches up a single whitespace character like space, newline, tab, return. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\S - &lt;/strong&gt;Uppercase S.  
   &lt;/td&gt;
   &lt;td&gt;
It matches up any character that is not a part of \s. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\d - &lt;/strong&gt;Lowercase d.  
   &lt;/td&gt;
   &lt;td&gt;
Matches decimal digit 0-9. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\D - &lt;/strong&gt;Uppercase D.  
   &lt;/td&gt;
   &lt;td&gt;
It matches any character that is not a decimal digit. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\t - &lt;/strong&gt;Lowercase t.  
   &lt;/td&gt;
   &lt;td&gt;
Matches tab. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\n - &lt;/strong&gt;Lowercase n.  
   &lt;/td&gt;
   &lt;td&gt;
Matches newline. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\r - &lt;/strong&gt;Lowercase r.  
   &lt;/td&gt;
   &lt;td&gt;
Matches return. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;\b - &lt;/strong&gt;Lowercase b.  
   &lt;/td&gt;
   &lt;td&gt;
It matches up only the beginning or end of the word. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;+&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Checks if the preceding character appears single or multiple times. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;*&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Scrutinizes if the preceding character appears zero or more times. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;?&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Matches zero or one occurrence. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;{}&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Checks for an explicit number of times. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;()&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Creates a group when performing matches. 
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;
&lt;strong&gt;&amp;lt;&amp;gt;&lt;/strong&gt; 
   &lt;/td&gt;
   &lt;td&gt;
Creates a named group when performing matches. 
   &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Note: The above table doesn't shed light on every aspect of RegEx. Don't bother if you can't wrap your head around all the meta-characters for now. With time and training, you will understand the uniqueness of these characters and learn when to use them. &lt;/p&gt;

&lt;p&gt;Python comes with a module named re to work with RegEx. The basic syntax of importing the RegEx module is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import re 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The RegEx mechanism comes with the module named &lt;code&gt;re&lt;/code&gt;, and it provides many functions. In this tutorial, I’m going to discuss the three most practical and widely used functions. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;re.match() Function&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;re.match()&lt;/strong&gt; function of the re module in Python searches for the regular expression pattern and returns the first occurrence. The Python RegEx Match function checks for a match only at the beginning of the string. Therefore, if a match is found in the first line, it immediately returns the matched object. However, if a match is seen in another line, the Python RegEx Match function returns null. Please allow me to show you a quick example now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import re 
pattern = "C" 
sequence1 = "IceCream" 
sequence2 = "Catch" 
print("Sequence 1: ", re.match(pattern, sequence1)) 
print("Sequence 2: ", re.match(pattern,sequence2).group()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sequence 1:  None 
Sequence 2:  C 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the function &lt;code&gt;re.match()&lt;/code&gt;returns a corresponding match object if zero or more characters (C) at the beginning of the string match the pattern. Else it returns None if the string does not match the given pattern. As you can see, we get an output of &lt;code&gt;None&lt;/code&gt; because it didn't find the pattern at the beginning of the first occurrence. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;re.search() Function&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;re.search()&lt;/strong&gt; function searches for the regular expression pattern and returns the first occurrence in a string. Unlike the &lt;strong&gt;re.match()&lt;/strong&gt; function, it checks all lines of the input string. The Python &lt;strong&gt;re.search()&lt;/strong&gt; function returns a match object when the pattern is found and is "&lt;strong&gt;null&lt;/strong&gt;” if the pattern is not found in the string.  &lt;/p&gt;

&lt;p&gt;Here is a simple example for your better understanding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import re 
patterns = ["Software testing", "Dan"] 
my_string = "Software testing is a tough job" 
for pattern in patterns: 
    print("Looking for '%s' in '%s' " % (pattern, my_string), end='') 


    if re.search(pattern,my_string): 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Here is a match case") 
    else: 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Not a match") 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Looking for 'Software testing' in 'Software testing is a tough job' Here is a match case 
Looking for 'Dan' in 'Software testing is a tough job' Not a match 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I set two patterns in the above python program and searched them into &lt;code&gt;my_string&lt;/code&gt;. For the first case, the function got a matching case. Therefore, it returned positive and negative for the second case. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;re.findall() Function&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In Python, the &lt;strong&gt;re.findall()&lt;/strong&gt; method returns a list of strings containing all the matching cases from the input text upon provided pattern. The &lt;strong&gt;re.search()&lt;/strong&gt; method quickly searches the provided text using the specified pattern and returns only the first occurrence. In contrast, the &lt;strong&gt;re.findall()&lt;/strong&gt; function iterates over all the lines of the file and returns all the non-overlapping matches of pattern in a single step. If the pattern is not found in the text, &lt;strong&gt;re.findall()&lt;/strong&gt; returns an empty list.  &lt;/p&gt;

&lt;p&gt;Let’s write a simple python program to understand the **re.findall() **function’s behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import re 
my_string1 = "Hello 10 Dan 20. Howdy? 30" 
my_string2 = "Hello Dan Howdy?" 
pattern = '\d+' 
result1 = re.findall(pattern, my_string1) 
result2 = re.findall(pattern, my_string2) 
print(result1) 
print(result2) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['10', '20', '30'] 
[] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you look closely into the above example, you'll find two different strings declared against a single pattern. For the first string, the &lt;strong&gt;re.findall()&lt;/strong&gt; function got a match and returned the value &lt;strong&gt;&lt;code&gt;['10', '20', '30'] &lt;/code&gt;&lt;/strong&gt; as per the pattern demand. On the other hand, the second string did not have the pattern available in it. Therefore, the function returned an empty list &lt;strong&gt;&lt;code&gt;[]&lt;/code&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Regular Expression is a vast topic, and it requires a lot of practice to become a master of it. In this tutorial, I tried to give you a quick review of RegEx and its essential functions. However, it has many advanced-level functions that you will know later on. Being proficient in RegEx and its functions, solving exercise is a must! &lt;/p&gt;

&lt;p&gt;Feel free to browse through the other sections of the blog where you can find many other amazing articles on: &lt;a href="https://www.jobsity.com/blog/tutorials" rel="noopener noreferrer"&gt;Programming&lt;/a&gt;, &lt;a href="https://www.jobsity.com/blog/it" rel="noopener noreferrer"&gt;IT&lt;/a&gt;, &lt;a href="https://www.jobsity.com/blog/outsourcing" rel="noopener noreferrer"&gt;Outsourcing&lt;/a&gt;, and even &lt;a href="https://www.jobsity.com/blog/management" rel="noopener noreferrer"&gt;Management&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interested in joining our amazing team and working with top U.S. based clients? Then apply &lt;a href="https://recruitment.jobsity.com/applylp" rel="noopener noreferrer"&gt;here&lt;/a&gt; and take your career to the next level.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>regex</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
