
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How not to match a character after repetition in Python Regex?
^ | # Beginning of string |
(?! | # Do not match if |
|2{1,2}5) | # Or there is one or two 2s followed by a 5 |
.* | # Anything else is accepted |
Example
The following code fulfils the conditions in given question
import re foo = '2249678' foo2 = '2259678' result = re.findall(r'^(?!2{1,2}5).*', foo) result2 = re.findall(r'^(?!2{1,2}5).*', foo2) print result print result2
Output
This gives the output
['2249678'] []
- Related Articles
- How to match any one uppercase character in python using Regular Expression?\n\n
- How to match any non-digit character in Python using Regular Expression?\n\n
- How to match any character using Java RegEx
- How to match nonword characters in Python using Regular Expression?\n\n\n\n
- How to match a non-word character using Java RegEx?
- How to add space before and after specific character using regex in Python?
- Posix character classes p{Lu} Java regex\n
- How to match n number of occurrences of an expression using Java RegEx?
- Insert a character after every n characters in JavaScript
- How to match a line not containing a word in Java Regex
- Python - Character repetition string combinations
- How to match a character from given string including case using Java regex?
- How to match at the end of string in python using Regular Expression?\n\n
- How to truncate character vector with three dots after n characters in R?
- MySQL Regex to match a pattern for ignoring a character in search like Chris.Brown?

Advertisements