
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

683 Views
Backslashes in Python regular expressions (regex) are used to define special sequences and escape characters. As backslashes are also used in Python strings, we need to be careful while using them. How Backslashes Work Now let us see how backslashes work in Python regular expressions - Escaping Characters: Some characters have specific meanings in regex (such as . or *). To treat them as normal characters, use a backslash (\.). ... Read More

1K+ Views
This article gives a guide on the difference between re.findall() and re.finditer() methods available in Python. The re module of Python helps in working with regular expressions. Both the re.findall() and re.finditer() methods are used to search for patterns, but they behave differently. Let us see the differences with simple explanations and examples in this article. Using re.findall() Method The re.findall() helps to get a list of all matching patterns. It searches from the start or end of the given string. If we use the findall() method to search for a pattern in a given string, it will return all occurrences ... Read More

3K+ Views
In this article, we are going to learn how to extract a URL from an HTML link using Python regular expressions. URL is an acronym for Uniform Resource Locator; it is used to identify the location resource on the Internet. URL consists of a domain name, path, port number, etc. The URL can be parsed and processed by using a Regular Expression. Therefore, if we want to use a Regular Expression, we have to use the "re" library in Python. Following is an example of a URL - URL: https://www.tutorialspoint.com/courses If we parse the above URL we can find ... Read More

3K+ Views
In this article, you will find out how to use the range in Python regular expressions. With the help of Python's regular expressions, you can search, match, and manipulate text efficiently. One useful feature in regex is ranges, so it helps us define sets of characters within square brackets "[ ]". Range in Regex In Python, a range is used when you want to match characters within a specific group. It is defined inside brackets "[ ]" with the help of a hyphen -. For example: # Matches any digit (0 to 9) pat1 = r"[0-9]" ... Read More

832 Views
In this article you will find to write regular expression in Python to find repeating digits in the given number. Regular expression is a special feature that helps you find matching parts of a string. It can find all repeated characters or digits in a number. Finding repeating digits can help in many areas like data analysis or validation. For example, check if a number like 1223 has repeated digits "2" or "3". So in this example 2 is the repeated digit. Let us see how you can perform this task practically using Python Regex. Regex Pattern for Repeated Digits ... Read More

1K+ Views
This article gives a guide on how to capture an exception raised by a regular expression in Python. We will also see simple example programs that show how to do this. Regular expressions are useful for matching patterns in text, but they may result in errors like incorrect syntax or mismatches. Python uses exception handling (try-except) to handle these errors to avoid errors. For example, if the given pattern is "[a-z", which is an incorrect pattern that can lead to an error showing that the character set is invalid, because the closing bracket ] is missing. Python Regex Exception ... Read More

773 Views
This article talks about how you can clear the regular expression cache in Python. Regular expressions in Python are used to find patterns in text, but they also use an internal cache to store frequently used expressions for faster execution. We may sometimes need to clear this cache to free up memory or reset stored patterns. You can do this using Python's re.purge() method. Why Clear Regex Cache? You need to clear the regex cache for the following reasons - Too many stored patterns may consume your system's memory. If you are dynamically updating regex patterns, deleting the cache ... Read More

114 Views
This article explains how to work with Regular Expressions (RegEx) in Python using the "re" module. RegEx is a sequence of characters that defines a search pattern. Below are different ways to use RegEx in Python. These are some of the essential methods in Python's re module that help with pattern matching, searching, replacing, and extracting data efficiently. Using the re.match() method Using the re.findall() method Using the re.search() method Using the re.sub() and re.subn() methods Using the re.split() method Using re.match() Method The re.match() method checks if a string matches a given pattern at the ... Read More

372 Views
This article will discuss how to compare regular expressions in Perl and Python. Regular expressions, or regex, are patterns used to match strings. Both Perl and Python support regex, but they have some differences in syntax and usage. For example, you write a regular expression like this in Perl - $text =~ /pattern/ But you write it like this in Python - re.search('pattern', text) So in the below section of this article will show the similarities and differences between Perl and Python regex with simple examples - ... Read More

467 Views
This article will discuss the difference between dot '.', question mark '?', and asterisk'*' in Python regular expressions. In regular expressions, '.' means any one character except the newline, '*' means zero or more times of the character or group before it. and '?' means zero or one time of the character or group before it. In some types of regex, ? Also makes things non-greedy. As we have seen in Python regular expressions, these symbols have different meanings, so let us understand these symbols using the examples - Usage of Dot (.) The following example will use ... Read More