3/10/2023 0 Comments Alphabet rejex pythonTarget_str = "Jessa salary is 8000$ She is Python developer" So ‘ thon‘ should be part of a larger word in our string, but not at the beginning of the word. So this sequence can be useful for matching and locating some strings in a specific word.įor example, let’s use \B to check whether the string ‘ thon‘ is inside the target string but not at the beginning of a word. On the other hand, the special sequence \B matches the empty string or the border between two alphanumeric characters or two non-alphanumeric characters only when it is not at the beginning or at the end of a word. This sequence is the exact opposite of \b. Therefore keep in mind that the word you’re trying to match with the help of the \b special sequence should be separate, not part of a word. Moreover, the \b sequence always matches the empty string or boundary between an alphanumeric character and a non-alphanumeric character. But we will not get a match because non-alphanumeric characters do not border it on both sides. No match will be returned if the word is contained inside another word.įor instance, considering the same target string, we can search for the word “ ssa” using a \b special sequence like this "\bssa\b". One essential thing to keep in mind here is that the match will be made only for the complete and separate word itself. Result = re.findall(r"\bthon\b", target_str) # \b need separate word not part of a word # \w to match all alphanumeric characters
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |