I am using python 3.4 in windows 7. I have excel sheet in which data is present in every cell. The data is of different kinds .Two examples :- "Qwert A_B_C_1 uiop"
and "Qwert A_X_Y_Z uiop"
To sum up i have to extract keywords which are written in CAPS where just after the first word an underscore is present. The extracting should stop once a whitespace is encountered
I have tried something like this but
x = "QWERT A_B_C_1 UIOP"
se = re.findall("[A-Z]+_[A-Z]+_[A-Z]+_[0-9A-Z]+",x)
But it is not working with different types of keywords.
[A-Z]+(?:_[A-Z]+)*_[A-Z0-9]+
You can use this to capture variable _[A-Z]
in between.See demo
import re
p = re.compile(r'[A-Z]+(?:_[A-Z]+)*_[A-Z0-9]+')
test_str = "QWERT A_B_C_1 UIOP\nQwert A_X_Y_Z uiop"
re.findall(p, test_str)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments