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

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1834 | 回復(fù): 5
打印 上一主題 下一主題

有人寫 in process regex 成功過嗎? 不會(huì)是 Cygwin 版本的 Bash 有什么不一樣吧? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-05-05 21:34 |只看該作者 |倒序?yàn)g覽
本帖最后由 dove-young 于 2010-05-05 21:37 編輯

我承認(rèn)我看過《十二篇》,也看過《十三問》了。但是我的確沒有看到關(guān)于 In process regex 的內(nèi)容。也許是我找的還不夠仔細(xì)。

不過這個(gè)東西看起來好像是挺郁悶的。 bash 的 manual page 和 維基百科 里面都說 bash 3.0 以后可以寫 in process 的 regex。我在我的 bash
3.2.49 里面卻怎么也寫不出可用的 regex 的樣例。

  1. $ bash --version
  2. GNU bash, version 3.2.49(23)-release (i686-pc-cygwin)
  3. Copyright (C) 2007 Free Software Foundation, Inc.
復(fù)制代碼

  1. $ if [[ 192.168.0.4 =~ '[0-9].*' ]] ; then echo 222; else echo 333; fi
  2. 333
  3. if [[ 192 =~ '[0-9].*' ]] ; then echo 222; else echo 333; fi
  4. 333
  5. if [[ 192 =~ '.*' ]] ; then echo 222; else echo 333; fi
  6. 333
  7. if [[ 192 =~ '/.*/' ]] ; then echo 222; else echo 333; fi
  8. 333
  9. if [[ 192 =~ /[0-9].*/ ]] ; then echo 222; else echo 333; fi
  10. 333
復(fù)制代碼
貌似只有一種情況才可以匹配

  1. if [[ 192 =~ 192 ]] ; then echo 222; else echo 333; fi
  2. 222
復(fù)制代碼
但是這就不再是 regex 了吧。。。。。。。 下面是 bash man page 里面截出來的內(nèi)容


  1. [[ expression ]]

  2.               An additional binary operator, =~, is available, with the same precedence as == and !=.  When it is used, the  string  to  the
  3.               right of the operator is considered an extended regular expression and matched accordingly (as in regex(3)).  The return value
  4.               is 0 if the string matches the pattern, and 1 otherwise.  If the regular expression is  syntactically  incorrect,  the  condi-
  5.               tional  expression's  return value is 2.  If the shell option nocasematch is enabled, the match is performed without regard to
  6.               the case of alphabetic characters.  Substrings matched by parenthesized subexpressions within the regular expression are saved
  7.               in the array variable BASH_REMATCH.  The element of BASH_REMATCH with index 0 is the portion of the string matching the entire
  8.               regular expression.  The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized sub-
  9.               expression.
復(fù)制代碼
下面是 維基百科 里面截出來的內(nèi)容

  1. 進(jìn)程內(nèi)的正則表達(dá)式

  2. bash 3.0 支持進(jìn)程內(nèi)的正則表達(dá)式,使用下面的語法 :

  3. [[ string =~ regex ]]

  4. 正則表達(dá)式語法同regex(7) man page 所描述的一致。正則表達(dá)式匹配字符串時(shí)上述命令的退出狀態(tài)為0,不匹配為1。正則表達(dá)式中用圓括號(hào)括起的子表達(dá)式可以訪問shell變量 BASH_REMATCH ,如下:

  5. if [[ abcfoobarbletch =~ 'foo(bar)bl(.*)' ]]
  6. then
  7.          echo The regex matches!
  8.          echo $BASH_REMATCH      -- outputs: foobarbletch
  9.          echo ${BASH_REMATCH[1]} -- outputs: bar
  10.          echo ${BASH_REMATCH[2]} -- outputs: etch
  11. fi

  12. 使用這個(gè)語法的性能要比生成一個(gè)新的進(jìn)程來運(yùn)行 grep 命令優(yōu)越,因?yàn)檎齽t表達(dá)式匹配在bash進(jìn)程內(nèi)完成。如果正則表達(dá)式或者字符串包括空格或者shell 關(guān)鍵字,(諸如 '*' 或者 '?'),就需要用引號(hào)包裹。
復(fù)制代碼
神啊!有人寫 in process regex 成功過嗎? 不會(huì)是 Cygwin 版本的 Bash 有什么不一樣吧?

論壇徽章:
5
獅子座
日期:2013-08-20 10:12:24午馬
日期:2013-11-23 18:04:102015年辭舊歲徽章
日期:2015-03-03 16:54:152015亞冠之德黑蘭石油
日期:2015-06-29 18:11:1115-16賽季CBA聯(lián)賽之新疆
日期:2024-02-21 10:00:53
2 [報(bào)告]
發(fā)表于 2010-05-06 07:01 |只看該作者
Linux下的bash4.1.5可以,我的minSYS的3.1.17不行……

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報(bào)曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
3 [報(bào)告]
發(fā)表于 2010-05-06 08:08 |只看該作者
''換""

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-05-06 13:56 |只看該作者
在cybwin bash3.2試了一下,
[[ s1 =~ s2 ]]
s1包含s2時(shí)為真,不能用規(guī)則表達(dá)式。

論壇徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年紀(jì)念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役紀(jì)念章
日期:2022-04-24 14:33:24
5 [報(bào)告]
發(fā)表于 2010-05-06 22:09 |只看該作者
這兩個(gè)系統(tǒng)行:
#if [[ abcfoobarbletch =~ 'foo(bar)bl(.*)' ]]; then echo matches; fi
matches
#bash --version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
#uname -a
SunOS t1000 5.10 Generic_118833-33 sun4v sparc SUNW,Sun-Fire-T1000 Solaris

#if [[ abcfoobarbletch =~ 'foo(bar)bl(.*)' ]]; then echo matches; fi
matches
#bash --version
GNU bash, version 3.00.16(1)-release (powerpc-ibm-aix5.1)
Copyright (C) 2004 Free Software Foundation, Inc.
#uname -a
AIX aix 3 5 00C97AC04C00 powerpc unknown AIX

這兩個(gè)系統(tǒng)不行:
#if [[ abcfoobarbletch =~ 'foo(bar)bl(.*)' ]]; then echo matches; fi
#bash --version
GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
#uname -a
Linux ubuntu 2.6.24-22-generic #1 SMP Mon Nov 24 19:35:06 UTC 2008 x86_64 GNU/Linux

#if [[ abcfoobarbletch =~ 'foo(bar)bl(.*)' ]]; then echo matches; fi
#bash --version
GNU bash, version 4.0.24(0)-release (amd64-portbld-freebsd7.2)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
#uname -a
FreeBSD freebsd.unix-center.net 7.2-RELEASE-p4 FreeBSD 7.2-RELEASE-p4 #0: Fri Oct  2 08:22:32 UTC 2009     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2010-05-07 13:16 |只看該作者
看來還是S了這條心了吧。。。。 有這種regex的東西還是pipe到sed/awk吧。。。。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP