I need the regex expression to find a substring (it’s a variable) that is either preceded/followed by punctuation, whitespaces or the start/end of the string. I don’t know the size or content of the substring. I’ve come up with [\?\.!\- ]1abc[\?\.!\- ] (this is a specific example where the substring is 1abc) but I don’t… Read More Python Regex Expression that finds variable string between whitespace, punctuation and/ or string end
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, ”, test_String) and this error was occured: error: error Traceback (most… Read More python regex lookbehind to remove _sublabel1 in string like "__label__label1_sublabel1"
I am new to python so I would like to get a few ideas for this. I am writing a function to find matching word patterns in a sentence and replace the spaces inside of only the matched words. Input: (c)variable ＜ var_CONST1(例 -125(N)) 【AAA BBB有】AND【技術企画】AND【AAA BBB CCC】 Expected Output: (c)variable ＜ var_CONST1(例 -125(N)) 【AAA-BBB有】AND【技術企画】AND… Read More More elegant way of replacing substring of text that was matched with regex
I have a python string that contains a list of words separated by either a plus or minus sign s = "AA + BB + 1C – CC – DD" I want to get a list of words with a plus sign which is below plusList = ["AA", "BB", "1C"] And a list with a… Read More Split a string with multiple delimiter & create a separate list
I have a template that I need to replace a part of that using Regex in Python. Here is my template: (Note that there is at least a new line between two comments) hello how’s everything <!–POSTS:START–> some text <!–POSTS:END–> Some code here I want to replace everything between <!–POSTS:START–> and <!–POSTS:END–> in Python. So… Read More Replace An Exact Grouped Part in RegEx Python
I’m wondering what the proper way to test if a named capture group exists. Specifically, I have a function that takes a compiled regex as a parameter. The regex may or may not have a specific named group, and the named group may or may not be present in a string being passed in: some_regex… Read More Python — check if named capture group exists