Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python capture in regex

import re

target_string = "The price of PINEAPPLE ice cream is 20"

# two groups enclosed in separate ( and ) bracket
result = re.search(r"([A-Z]+).+(d+)", target_string)

# Extract matching values of all groups
print(result.groups())
# Output ('PINEAPPLE', '20')

# Extract match value of group 1
print(result.group(1))
# Output 'PINEAPPLE'

# Extract match value of group 2
print(result.group(2))
# Output 20
Comment

PREVIOUS NEXT
Code Example
Python :: how to convert month to number in python 
Python :: import numpy Illegal instruction (core dumped) 
Python :: how to find if a value is even or odd in python 
Python :: series datetime64 seconds to 0 
Python :: add authorization header in python requests 
Python :: plt plot circle 
Python :: pytesseract pdf to text 
Python :: selenium python switch to iframe 
Python :: get attribute in selenium python 
Python :: xgboost feature importance 
Python :: get self file name in python 
Python :: how to write to an output file in pytion 
Python :: datetime one month ago python 
Python :: remove x label matplotlib 
Python :: select python version ubuntu 
Python :: required validator python WTForms 
Python :: convert dictionary keys to int python 
Python :: Traceback (most recent call last): File "/usr/bin/pip", line 9, in <module from pip import main 
Python :: python months between two dates 
Python :: update python 3.10 ubuntu 
Python :: python program that takes command line arguments as input and print the number of arguments 
Python :: load ui file pyqt5 
Python :: stop server django programmatically 
Python :: pyqt5 wait cursor 
Python :: skimage image read 
Python :: how to order randomly in django orm 
Python :: convert transformation matrix to pose ros 
Python :: pandas series draw distribution 
Python :: how to take user input in a list in python 
Python :: token_obtain_pair check email 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =