我将如何进行如下所示的正则表达式匹配,但在(“^This”)周围加上引号,就像在现实世界中“This”将是一个可以在其中包含空格的字符串。
#!/bin/bash
text="This is just a test string"
if [[ "$text" =~ ^This ]]; then
echo "matched"
else
echo "not matched"
fi
我想做类似的事情
if [[ "$text" =~ "^This is" ]]; then
但这不匹配。
您可以使用\
在空格之前。
#!/bin/bash
text="This is just a test string"
if [[ "$text" =~ ^This\ is\ just ]]; then
echo "matched"
else
echo "not matched"
fi
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)