+ 2
Regex with python
Hi people! Can anyone tell me how would I use regex in python. For exemple I want to check if a word is in a dictionary that has a word on every line. If âhoneâ in open(âdictionary.txtâ).read(): Print(âfound!â) This would print âfound!â even if it finds word âphoneâ or âhoneyâ in dictionary As a linux guy I know how it would be done with grep and regex grep â^word$â dictionary.txt How can I do that in python? Thanks!
6 RĂ©ponses
+ 6
I wrote a code on some RegEx examples quite a time ago. Perhaps you'll make a use of it.
https://code.sololearn.com/c40z8B7tOdCN/?ref=app
+ 3
If you have a string that looks like:
st = âphone\nhoneyâ
You can do:
lis = st.split(â\nâ)
It returns a list of strings: âphoneâ and âhoneyâ. Then you can search the list, and you wonât have that problem.
+ 2
here is an example code:
https://code.sololearn.com/chVPELy79OK3/?ref=app
+ 1
Lets say I have a string âoneâ and I want to check if that string is in a dictionary. But I want it to follow these rules when checking:
A line must start with that string
A line must end with that string
Correct:
(Start of line)one(end of line)
Wrong:
(Start of line)phone(end of line
In both these cases the example i have gave you will find it
0
đđđ
Thanks man! Exectly what I was looking for!!!