regex和grep仅匹配只有一位或两位数的字符串 [英] regex and grep match only string with only single or double digit

查看:33
本文介绍了regex和grep仅匹配只有一位或两位数的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提取仅包含一位或两位数数字的字符串.我的文件(测试)看起来像

I need to extract a string with only single or double digit number in them. my file (test) looks like

test1correct
test12something
test123wrong

在上面的示例中,我只想grep用于test1correct和test12something

In the above example, i want to grep only for test1correct and test12something

我尝试了这个grep"test [0-9] {1,2}"测试,但是它给了我全部3行.

I tried this grep "test[0-9]{1,2}" test but it gives me all the 3 lines.

推荐答案

使用: grep"test [0-9] {1,2} [^ 0-9] "

这篇关于regex和grep仅匹配只有一位或两位数的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆