String 字符串比较错误
我尝试编写一组函数来检查域名的过期日期:String 字符串比较错误,string,common-lisp,String,Common Lisp,我尝试编写一组函数来检查域名的过期日期: (ql:quickload 'inferior-shell) (defun whois-lookup (site) (let ((request (format nil "whois ~a" site))) (inferior-shell:run/ss request))) (defun match-expiration-string (input) (let ((test-string "Registrar Registration
(ql:quickload 'inferior-shell)
(defun whois-lookup (site)
(let ((request (format nil "whois ~a" site)))
(inferior-shell:run/ss request)))
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(string> input test-string)))
(defun domain-expiration-date (site)
(with-input-from-string (input (whois-lookup site))
(loop for line = (read-line input nil nil)
while line do
(when (match-expiration-string line)
(format t "~A~%~t~A ~%" site line)))))
我这样称呼它:(域名到期日期“startpage.com”)
不幸的是,它不只是显示相关的行,而是显示所有行
匹配过期字符串
似乎工作正常,所以我不知道问题出在哪里
CL-USER> (match-expiration-string "Registrar Registration Expiration Date: 2016-05")
39 (6 bits, #x27, #o47, #b100111)
CL-USER> (match-expiration-string "Registrar Registration Expiration ")
NIL
正如jkiiski所建议的,它使用正则表达式:
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(ppcre:scan test-string input)))
==>
正如Joshua Taylor所说,您不需要正则表达式,只需要
search
。我还注意到“注册人注册截止日期:”并不是出现在每个whois响应中,因此我修改了搜索(并在我需要其他类型域的其他搜索字符串时进行了替换):
正如jkiiski所建议的,它使用正则表达式:
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(ppcre:scan test-string input)))
==>
正如Joshua Taylor所说,您不需要正则表达式,只需要
search
。我还注意到“注册人注册截止日期:”并不是出现在每个whois响应中,因此我修改了搜索(并在我需要其他类型域的其他搜索字符串时进行了替换):
(字符串>“a”注册人注册到期日期:)=>0
。您应该使用STRING=
(带有必要的关键字参数)检查子字符串是否完全匹配。或者使用正则表达式。有意义。我有一个使用string=
的版本可以工作,但显然只有在行足够长的情况下才能工作。这就是正则表达式!谢谢大家!<代码>(字符串>“a”注册到期日期:)=>0。您应该使用STRING=
(带有必要的关键字参数)检查子字符串是否完全匹配。或者使用正则表达式。有意义。我有一个使用string=
的版本可以工作,但显然只有在行足够长的情况下才能工作。这就是正则表达式!非常感谢。与正则表达式不同,简单的字符串包含就足够了。即使用。文档中的示例甚至是基于在另一个字符串中查找一个字符串。与正则表达式相比,简单的字符串包含就足够了。即使用。文档中的示例甚至基于在另一个字符串中查找一个字符串。
(defun match-expiration-string (input)
(let ((inclusion-strings '("Expiration Date:"))
(exclusion-strings '("Registrar Registration Expiration Date:")))
(when (some #'(lambda (s) (search s input))
inclusion-strings)
(notany #'(lambda (s) (search s input))
exclusion-strings))))