python-regex

python regex lookbehind to remove _sublabel1 in string like "__label__label1_sublabel1"

python regex lookbehind to remove _sublabel1 in string like "__label__label1_sublabel1" Question: i have dataset that prepare for train in fasttext and i wanna remove sublabels from dataset for example: __label__label1_sublabel1 __label__label2_sublabel1 __label__label3 __label__label1_sublabel4 sometext some sentce som data. Any help much appreciated thanks im tried this: r'(?<=__label__[^_]+)w+’ isnt working exact code: ptrn = r'(?<=__label__[^_]+)w+’ re.sub(ptrn, …

Total answers: 1

Regular Expression with Two Names: One With Middle Initial and One Without

Regular Expression with Two Names: One With Middle Initial and One Without Question: I’m attempting to identify the names in this string, using regex (https://regex101.com). Example text: Elon R. Musk (245)436-7956 Jeff Bezos (235)231-3432 What I’ve tried so far only seems to work for names without a middle initial: ([A-Z]{1}[a-z]+) ([A-Z]{1}[a-z]+) Note: Phone Numbers are …

Total answers: 2

re.sub replace with matched content

re.sub replace with matched content Question: Trying to get to grips with regular expressions in Python, I’m trying to output some HTML highlighted in part of a URL. My input is images/:id/size my output should be images/<span>:id</span>/size If I do this in Javascript method = ‘images/:id/size’; method = method.replace(/:([a-z]+)/, ‘<span>$1</span>’) alert(method) I get the desired …

Total answers: 4