+ 1
Python - re library
i taken a word and need to search this literal in a text, like that word = "some" text = "this is some text" i use search method: regex = r"/"+word+"/" if re.search(regex, text) : tararara wich returns None Thanks.
2 Respuestas
0
regex = "some" will work fine. You don't need to surround the word with "/"s in Python. But this will also match "some" in the word "something" too.
If you need "some" to appear as a standalone word, you can require it to be surrounded with whitespace. regex = "\s" + word + "\s" will do this.
0
Ok