PHP解析输入域名的textarea(以空格、逗号、换行符分隔)
对于我的用户,我需要呈现一个屏幕,他们可以在文本区域中输入多个域名。用户可以将域名放在不同的行上,或者用空格或逗号分隔它们(甚至可能是分号 - 我不知道!)
我需要解析和识别具有扩展名的各个域名(这将是 .com,其他任何域名都可以)被忽略)。
用户输入可以是:
asdf.com
qwer.com
AND/OR
wqer.com, gwew.com
AND/OR
ertert.com gdfgdf.com
没有人会输入像 www.abczone.com 这样的 3 级域名,但如果他们这样做我只对提取 abczone.com 部分感兴趣。 (我可以有一个单独的正则表达式来验证/提取每个正则表达式)。
For my users I need to present a screen where they can input multiple domain names in a textarea. The users can put the domain names on different lines, or separate them by spaces or commas (maybe even semicolons - I dont know!)
I need to parse and identify the individual domain names with extension (which will be .com, anything else can be ignored).
User input can be as:
asdf.com
qwer.com
AND/OR
wqer.com, gwew.com
AND/OR
ertert.com gdfgdf.com
No one will input a 3 level domain like www.abczone.com, but if they do I'm only interested in extracting the abczone.com part. (I can have a separate regex to verify/extract that from each).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将做到这一点:
“查找一个字母的所有序列,后跟字母、数字或连字符,后跟
.com
,然后是一个单词分隔符。”(您需要最后一点来防止从
bim.command.com
获取bim.com
。)Python 测试用例,因为我没有 PHP 测试环境手:
This will do it:
"Find all sequences of a letter followed by letters, digits, or hyphens, followed by
.com
then a word break."(You need the last bit to protect against picking up
bim.com
frombim.command.com
.)Python test case because I don't have a PHP test environment to hand:
在这里,如果您愿意,可以使用 i 修饰符并删除所有大写 AZ:
Here it is, you can use the i modifier and delete all the uppercase A-Z if you want to: