如何检查字符串是否与域的字符串匹配

时间:2015-06-17 18:34:25

标签: regex bash shell

我编写了一段代码来测试字符串是否与这样的域匹配:

capitalizeFirstLetter("hello to the world");

this website的帮助下,但出于某种原因,上述情况无效。

你知道为什么吗?

1 个答案:

答案 0 :(得分:1)

Bash正则表达式没有外观,您可以将Perl Regex与grep一起使用:

#!/bin/bash
if grep -oP '^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$' <<< "$1" >/dev/null 2>&1;then
echo valid
else
echo invalid
fi
相关问题