filmov
tv
Python Regex: How Find a Substring in a String

Показать описание
↓ Code Available Below! ↓
This video shows how to find and extract substrings within python strings using the regular expressions package. Locating and extracting substrings from larger strings is a common task in text data processing; Python makes it easy to do these sorts of text data processing tasks.
If you find this video useful, like, share and subscribe to support the channel!
**Note** if you want to match a specific substring (such as a specific word) and not a regular expression pattern, just pass that word or substring in as the "pattern" argument.
Code used in this Python Code Clip:
import re
lines = '''
Nappa - What does the scouter say about his power level?
Vegeta - It's over 9000!
Nappa - What 9000? That can't be right. Can it?
'''
string = lines)
first_match
# Extract the matched string from the match:
# Extract the index positions of the start and end:
string = lines)
for match in all_matches:
string = lines)
all_match_list
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
This video shows how to find and extract substrings within python strings using the regular expressions package. Locating and extracting substrings from larger strings is a common task in text data processing; Python makes it easy to do these sorts of text data processing tasks.
If you find this video useful, like, share and subscribe to support the channel!
**Note** if you want to match a specific substring (such as a specific word) and not a regular expression pattern, just pass that word or substring in as the "pattern" argument.
Code used in this Python Code Clip:
import re
lines = '''
Nappa - What does the scouter say about his power level?
Vegeta - It's over 9000!
Nappa - What 9000? That can't be right. Can it?
'''
string = lines)
first_match
# Extract the matched string from the match:
# Extract the index positions of the start and end:
string = lines)
for match in all_matches:
string = lines)
all_match_list
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
Комментарии