bash regrex operator =~
来源:互联网 发布:xnview mac 破解 编辑:程序博客网 时间:2024/06/04 19:10
If you're using a recent bash (v3+) suggest bash regex comparison operator =~
, i.e.
if [[ "$HOST" =~ ^user.* ]]; then echo "yes"
fi
To match this or that
in a regex use |
, i.e.
if [[ "$HOST" =~ ^user.*|^host1 ]]; then echo "yes"fi
----------
The =~ Regular Expression matching operator within a double brackets test expression. (Perl has a similar operator.)
#!/bin/bashvariable="This is a fine mess."echo "$variable"# Regex matching with =~ operator within [[ double brackets ]].if [[ "$variable" =~ T.........fin*es* ]]# NOTE: As of version 3.2 of Bash, expression to match no longer quoted.then echo "match found" # match foundfiOr, more usefully:
#!/bin/bashinput=$1if [[ "$input" =~ "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" ]]# ^ NOTE: Quoting not necessary, as of version 3.2 of Bash.# NNN-NN-NNNN (where each N is a digit).then echo "Social Security number." # Process SSN.else echo "Not a Social Security number!" # Or, ask for corrected input.fi
refer the link
http://tldp.org/LDP/abs/html/bashver3.html#REGEXMATCHREF
0 0
- bash regrex operator =~
- linux 脚本 提示 -bash: [: ==: unary operator expected 解决办法
- Linux: Unary Operator Expected (Bash Script Error)
- operator =
- C++基础---string类的operator==/operator!=/operator</operator<=/operator>/operator>=/compare
- C++ 操作符重载 operator = 、operator <
- C++ 操作符重载 operator = 、operator <
- operator ==
- copy constructor & operator =
- 理解 operator=
- operator=函数.
- 警惕operator =
- operator= 的思考
- => Operator (C# Reference)
- => Operator (C# Reference)
- C++中operator =
- operator=相关思考
- qmake "The *= operator"
- 结巴分词源代码解析(二)
- 记录一些未解决的问题
- show bash version
- Linux进程控制命令之ps
- 黑马程序员——动态内存
- bash regrex operator =~
- OC视频笔记3.6(字符串常用方法)3.7(可变字符串的常用方法)
- 载波通信模块的代码分析
- 【C++总结】对象和类,this指针
- css clear用法
- 沙美中文离线地图App上线
- jquery中extend的实现
- 第十二周项目1 - 教师兼干部类
- WIN7下开机欢迎界面去掉画面下方"windows 7 旗舰版"