regex - Python: Replace string with prefixStringSuffix keeping original case, but ignoring case when searching for match -
So what I'm trying to do is "code" with "code" in "
Example:
myString = "HI There you need more for that job. Hi Hi."
keyword = "Hello"
I would like the result:
result = " HI
I do not know until keyword type typing The keyword until the query does not address the corpus (mestring).
I have found a solution that works most of the time, False positive, ie "
The closest I've come to is using a slightly derived version of this: But I still can not figure out how to do the second string to fix all the false positives described above. Close to
Or using NLTK's WordPunctTokenizer (which simplifies things like punctuation marks) but I'm not sure how sentences are put back together, it does not have a reverse function And I want to put the original punctuation required by my string, making a combination of all the tokens does not return the original string. For example, I would not want to replace "7-7" with "7-7", when the text "7-7" would have to be recreated token in its original text.
Hope that was clear enough seems like a simple problem, but it turned out to be more difficult then I thought
Is this OK?
& gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; MyString = "Hi there you need that person more for the job. Hi Hi." & Gt; & Gt; & Gt; Keyword = "hi" & gt; & Gt; & Gt; Search = re.compile (r '\ b (% s) \ b'% keyword, again.) & Gt; & Gt; & Gt; Search.sub ('& lt; b & gt; \ 1 1 & lt; / b & gt;', myString) '& lt; B & gt; Hi & lt; / B & gt; Are you there You should do more for that job & Lt; P & gt; Hi & lt; / P & gt; & Lt; P & gt; Hi & lt; / P & gt; ' The whole thing is to use the key, and.
Comments
Post a Comment