Using regular expressions – documentation for further reference
import re
text = 'gfgfdAAA1234ZZZuijjk'
m = re.search('AAA(.+?)ZZZ', text)
if m:
found = m.group(1)
# found: 1234
or:
import re
text = 'gfgfdAAA1234ZZZuijjk'
try:
found = re.search('AAA(.+?)ZZZ', text).group(1)
except AttributeError:
# AAA, ZZZ not found in the original string
found = '' # apply your error handling
# found: 1234
Related Posts:
- How do I get a substring of a string in Python?
- Substring in excel
- Does Python have a string ‘contains’ substring method?
- Does Python have a string ‘contains’ substring method?
- Pythonic way to create a long multi-line string
- Find the nth occurrence of substring in a string
- How do I lowercase a string in Python?
- Understanding the main method of python [duplicate]
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Convert bytes to a string
- Replacing instances of a character in a string
- Changing one character in a string
- How to read a file line-by-line into a list?
- strip(char) on a string
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How to check whether a string contains a substring in JavaScript?
- Converting integer to string in Python
- Reverse a string in Python
- How do I compare two strings in python?
- Python Math – TypeError: ‘NoneType’ object is not subscriptable
- working of \n in python [duplicate]
- ValueError: could not convert string to float: id
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- TypeError: not all arguments converted during string formatting python
- PermissionError: [Errno 13] in Python
- Extract substring in Bash
- ‘str’ object does not support item assignment
- How do I append one string to another in Python?
- How do I append one string to another in Python?
- How do I check if a string contains a specific word?
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- “If not” condition statement in python
- syntaxerror: “unexpected character after line continuation character in python” math
- How can I sort a dictionary by key?
- How to read a text file into a string variable and strip newlines?
- Convert bytes to a string
- How to print like printf in Python3?
- How to read a text file into a string variable and strip newlines?
- Check if a string contains a string in C++
- Python Logic of ListNode in Leetcode
- How can I write a `try`/`except` block that catches all exceptions?
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Plot logarithmic axes with matplotlib in python
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- How to remove punctuation in python?
- Split a string into 2 in Python
- Replace part of a string with another string
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- Error in Python script “Expected 2D array, got 1D array instead:”?
- Python Key Error=0 – Can’t find Dict error in code
- Relative imports for the billionth time
- How do I use the yfinance API in Python to get today’s DJI open?
- what does the __file__ variable mean/do?
- How to check if the string is empty?
- How to find all occurrences of a substring?
- Split string on whitespace in Python
- How do I check if a string contains a specific word?
- How do I convert a list of ascii values to a string in python?
- How to check whether a str(variable) is empty or not?
- Python TypeError: not enough arguments for format string
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- What does the ‘b’ character do in front of a string literal?
- How to add a string in a certain position?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- How can I concatenate str and int objects?
- What does the ‘b’ character do in front of a string literal?
- Proper shebang for Python script
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- Best way to replace multiple characters in a string?
- Convert columns to string in Pandas
- How do I correctly clean up a Python object?
- Log to the base 2 in python
- How to delete a character from a string using Python
- Python: Get the first character of the first string in a list?
- How to convert string to binary?
- Remove the first character of a string
- How to get the filename without the extension from a path in Python?
- sprintf like functionality in Python
- Convert hex to binary
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- What is the difference between String.subString() and String.subSequence()
- Implement touch using Python?
- Python setup.py develop vs install
- Java – removing first character of a string
- How to clamp an integer to some range?
- How does String substring work in Swift
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character