Found 26504 Articles for Server Side Programming

How to write a Python regular expression that matches floating point numbers?

Nikitasha Shrivastava
Updated on 06-Jun-2025 15:26:39

1K+ Views

This article will discuss how to write a Python regular expression that matches floating point numbers. We will try to create a regular expression pattern that can match any floating point number. So the regex we are going to create should also match integers and floating point numbers in which the integer part is not given. A floating-point number can be look like - Whole numbers with decimals like 3.14, 1.5, 12.10, Negative numbers like -2.55, -1.003, Numbers with optional zeros like 007.5, .75. Regex Pattern for Floating Point Number Here is the regular expression pattern ... Read More

How to write a Python Regular Expression to validate numbers?

Nikitasha Shrivastava
Updated on 06-Jun-2025 15:28:01

330 Views

Here, we will learn how to write a regular expression for validating a number in Python. As you may know Python has a module called re module for working with regular expression easily using the built-in functions. The re.match() function matches or validate the regex pattern with the given number. There are several ways to validate a number using regular expression, such as - Validate Integer Number Validate Real Number Validate Comma Separated Numbers Example: Validate Integer Number The following example will use different integer values to validate that they are numbers or not. We are ... Read More

How to write a Python regular expression to use re.findall()?

Nikitasha Shrivastava
Updated on 26-May-2025 17:51:57

489 Views

This article will explain how to write a Python regular expression to use re.findall() method. Regular expression, or regex, is used insearching and extracting patterns in text. Python provides the re module to work with regex, and re.findall() to find all matches of a pattern in a string. The re.findall() method returns a list of all occurrences of a pattern. It works with strings for extracting data. And it supports metacharacters for pattern matching. There are various ways to use the re.findall() method in Python, such as - Finds One or More Digits Find All Words in a String Extract ... Read More

How do backslashes work in Python Regular Expressions?

Nikitasha Shrivastava
Updated on 26-May-2025 17:15:27

684 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

What is the difference between re.findall() and re.finditer() methods available in Python?

Rajendra Dharmkar
Updated on 26-May-2025 17:01:49

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

How to use Python Regular expression to extract URL from an HTML link?

Nikitasha Shrivastava
Updated on 26-May-2025 18:04:33

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

How to use range in Python regular expression?

Nikitasha Shrivastava
Updated on 26-May-2025 18:00:53

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

How to write Python Regular Expression find repeating digits in a number?

Nikitasha Shrivastava
Updated on 06-Jun-2025 14:58:23

835 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

How to capture an exception raised by a Python Regular expression?

Nikitasha Shrivastava
Updated on 26-May-2025 18:15:13

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

How do I clear the regular expression cache in Python?

Nikitasha Shrivastava
Updated on 26-May-2025 18:11:32

776 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

Advertisements