亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 求教:正則問題 [打印本頁]

作者: jiejie455    時間: 2011-11-03 10:52
標題: 求教:正則問題
Bash RE:不包含某一特定的字符串,應(yīng)該怎么表示?
[^ ]* 只對單個字符有效. 想當然的[^(Character String)]*不行。 求解惑!
作者: blackold    時間: 2011-11-03 12:34
回復(fù) 1# jiejie455


    太寬泛了。

   反/負匹配。
作者: jiejie455    時間: 2011-11-03 12:49
本帖最后由 jiejie455 于 2011-11-03 13:16 編輯

回復(fù) 2# blackold


    謝謝回復(fù)。

那我編了個具體點的例子:

A test this is a test this is a test this is a test

正則匹配第一個this,前的字符串。也就是結(jié)果為: A test。

求用Sed解決。

4,5,6樓的都不錯,尤其是4樓的很巧妙。

但是我現(xiàn)在要厚臉皮擠點牙膏了:
如何匹配第一個this 和第二個this之間的字符串呢。 也就是 "is a test". 仍然求用SED解決。
作者: yinyuemi    時間: 2011-11-03 12:55
echo 'A test this is a test this is a test this is a test' |sed ':a;s/\(.*\)this.*/\1/;ta'
A test
作者: jason680    時間: 2011-11-03 13:01
$ echo 'A test this is a test this is a test this is a test' |sed 's/this.*//'
A test
作者: _man_mk_    時間: 2011-11-03 13:05
sed -n -e 's/this//2g'  -e 's/\(.*\)this.*/\1/p' file

比價笨的方法。
作者: lkk2003rty    時間: 2011-11-03 14:10
  1. echo "A test this is a test this is a test this is a test" | sed -r 's/.*?this(.*?)this.*/\1/'
復(fù)制代碼

作者: _man_mk_    時間: 2011-11-03 14:30
若若的問一句:

sed 里邊 a 出現(xiàn)3次以上 可以這樣寫。

a\{3\}

如果 this整個字符串出現(xiàn)  3次以上 ,要怎么寫?
作者: Shell_HAT    時間: 2011-11-03 14:35
回復(fù) 8# _man_mk_
  1. echo this thisthisthis this | sed -r 's/(this){3}//g'
復(fù)制代碼

作者: yinyuemi    時間: 2011-11-03 14:46
echo 'A test this 1is a test this 2is a test this 3is a test this 4is a test' |sed -r 's/this/#/g;s/([^#]*#){2} ([^#]*).*/\2/'
2is a test
作者: yuloveban    時間: 2011-11-03 14:59
若若的問一句:

sed 里邊 a 出現(xiàn)3次以上 可以這樣寫。

a\{3\}

如果 this整個字符串出現(xiàn)  3次以上 ...
_man_mk_ 發(fā)表于 2011-11-03 14:30


sed -r 's/a{2}//g' 就可以了
    在sed 里面 a{3} 的大括號是不用打上反斜杠的\吧!




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2