搜索确切字符串的正确命令是什么,
我尝试过startswith、find、re.sub,但似乎都是找到与其部分匹配的字符串。 iam 寻找命令,该命令搜索 iam 在给定文件中搜索的确切字符串。
感谢您的帮助。
i have tried startswith , find , re.sub but all seems to be find that string that matches part of it . iam looking for command which searchs the exact string which iam searching for in a given file.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测您要问什么,但我认为您想要的是在文件中找到精确的文本行。如果是这种情况,有几种方法可以做到这一点。
使用正则表达式来匹配行的开头和结尾:
使用直接 Python 查找行:(
小心处理行结尾。)
同样,这是对您想要询问的内容的猜测。
I'm guessing as to what you're asking about, but I think what you're wanting is to find an exact line of text in a file. If that's the case, there are a couple of ways to do it.
Use a regex to match start and end of line:
Find the line using straight Python:
(Take care in handling your line endings.)
Again, this is a guess as to what you're trying to ask.