Programming Articles

Page 651 of 2547

What does "?:" mean in a Python regular expression?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 2K+ Views

In Python regular expressions, the ?: syntax creates a non-capturing group. This allows you to group parts of a pattern without storing the matched text for later retrieval. What are Non-Capturing Groups? A non-capturing group groups regex tokens together but doesn't create a capture group that you can reference later. The syntax is (?:pattern) where ?: immediately follows the opening parenthesis. Example import re # Non-capturing group pattern = r'Set(?:Value)' text = "SetValue" match = re.search(pattern, text) if match: print(f"Full match: {match.group(0)}") print(f"Number of groups: ...

Read More

How to write Python regular expression to match with file extension?

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 1K+ Views

Using Python, we can easily search for specific types of files from a mixed list of file names using regular expressions. For this, we need to import Python's built-in module called re using the import keyword. The Regular expression or Regex is a special sequence of characters like \, *, ^, etc, which are used to search for a pattern in a string or a set of strings. It can detect the presence or absence of characters by matching them with a particular pattern and can also split a string into one or more substrings. Importing the Regex ...

Read More

How to extract data from a string with Python Regular Expressions?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 1K+ Views

In this article you will find out how to extract data from a string with Python Regular Expressions. In Python, extracting data from the given string is a common task. Regular expressions (regex) offer pattern-matching functionality to get and identify specific parts of a string. Python's re module helps in working with regex easily. The common functions of this module are re.search(), re.findall() and re.match() to make it easier to extract desired data. Common Regular Expression Functions Function Purpose Returns re.findall() Find all matches List of strings re.search() Find first match ...

Read More

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

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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. A regular expression for floating point numbers should match integers and floating point numbers where the integer part might be optional. A floating-point number can 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 Basic Regex Pattern for Floating Point Numbers Here is the regular expression pattern for ...

Read More

How to write a Python Regular Expression to validate numbers?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 448 Views

Regular expressions provide powerful pattern matching for validating different number formats in Python. The re module offers functions like re.match() to check if strings conform to numeric patterns. There are several common approaches to validate numbers using regular expressions ? Validate Integer Numbers Validate Real Numbers (Decimals) Validate Comma-Separated Numbers Validate Integer Numbers To validate integers, we use the pattern ^[+-]?\d+$ which matches optional sign followed by one or more digits ? import re # Test different integer values numbers = ["123", ...

Read More

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

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 655 Views

This article will explain how to write a Python regular expression to use re.findall() method. Regular expression, or regex, is used in searching 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 supports metacharacters for pattern matching. There are various ways to use the re.findall() method in Python, such as − Find One or More Digits Find All Words ...

Read More

How do backslashes work in Python Regular Expressions?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 847 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 Here's how backslashes function 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
Rajendra Dharmkar
Updated on 24-Mar-2026 2K+ Views

This article guides you through 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() method returns a list of all matching patterns found in the string. It searches through the entire string and collects all non-overlapping matches. Example Here is an example to show the usage of the findall() ...

Read More

How to use range in Python regular expression?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 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, which 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
Nikitasha Shrivastava
Updated on 24-Mar-2026 1K+ Views

In this article, you will learn to write regular expressions in Python to find repeating digits in a given number. Regular expressions are a powerful feature that helps you find matching patterns in strings. Finding repeating digits is useful in many areas like data validation, pattern recognition, and number analysis. For example, in the number 1223, we can identify that "22" contains repeating digits. Understanding the Regex Pattern To find repeating digits, we use the pattern r'(\d)\1+': (\d) − Captures a single digit in a group \1+ − Matches one or more occurrences of the ...

Read More
Showing 6501–6510 of 25,466 articles
« Prev 1 649 650 651 652 653 2547 Next »
Advertisements