Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to extract data from a string with Python Regular Expressions?
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 MoreHow to write a Python regular expression that matches floating point numbers?
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 MoreHow to write a Python Regular Expression to validate numbers?
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 MoreHow to write a Python regular expression to use re.findall()?
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 MoreHow do backslashes work in Python Regular Expressions?
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 MoreWhat is the difference between re.findall() and re.finditer() methods available in Python?
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 MoreHow to use range in Python regular expression?
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 MoreHow to write Python Regular Expression find repeating digits in a number?
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 MoreHow to capture an exception raised by a Python Regular expression?
This article provides a guide on how to capture exceptions raised by regular expressions in Python. We will explore simple example programs that demonstrate proper error handling techniques. 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 blocks) to handle these errors gracefully and prevent program crashes. For example, if the given pattern is "[a-z", this is an incorrect pattern that will raise an error because the closing bracket "]" is missing from the character set. Python Regex Exception Type ...
Read MoreHow to compare regular expressions in Perl and Python?
This article compares regular expressions in Perl and Python, showing syntax differences and practical examples. Regular expressions are patterns used to match and manipulate strings in both languages. The key difference is syntax: Perl uses $text =~ /pattern/ while Python uses re.search('pattern', text). Let's explore practical examples comparing both approaches. Check if a String Contains a Word Both languages can search for specific words in text, but use different syntax. Python Example Python uses the re.search() function to find patterns in strings ? import re text = "Hello Tutorialspoint" match = re.search(r"Tutorial", ...
Read More