2016-05-30 5 views
3

私はtcl 8.0 verisonでこの機能を実行しています。異なる回答を与えるtclの異なるバージョン

proc test {} { 
    set owner 212549316 
    set val [regexp {[0-9]{9}} $owner] 
    puts $val 
} 

TCL 8.6で同じコード、出力1であるが、TCL 8.0でそれが0あります。 文字列にtcl 8.0の文字列が9桁しか含まれていないかどうかを確認しています。

tcl 8.0 verisonでどのように動作させるかを助けてください。

+0

興味深い。 '[0-9] \ {9 \}'はTcl 8.0で期待される結果を生み出しますか? [私が見る](http://www.wellho.net/regex/tcl.html)から、バージョン8.1でTclに量制限子が導入されました。 –

+0

@wiktorStribiżewこれは、tclの両方のバージョン、つまり8.0と8.6で0を与えています。 http://www.tcl.tk/man/tcl8.0/TclCmd/regexp.htm: – Ash

+0

だから、制限(または* *バインド)量指定子はただのTcl 8.0 –

答えて

4

は、Tcl 8.0では、are not supportedを数量詞(を制限またはを結合しました。バウンド数量が高度な正規表現構文の導入でのTcl 8.1以降でサポートされて

set val [regexp {[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]} $owner] 

:Tclの8.0で9桁の数字を一致させるには

、あなたは[0-9] 9回繰り返す必要があるだろう。 Tclの8.0で利用可能な

基本的な正規表現の構文は含まれています:

. Matches any character. 
* Matches zero or more instances of the previous pattern item. 
+ Matches one or more instances of the previous pattern item. 
? Matches zero or one instances of the previous pattern item. 
() Groups a subpattern. The repetition and alternation operators apply to the preceding subpattern. 
| Alternation. 
[ ] Delimit a set of characters. Ranges are specified as [x-y]. If the first character in the set is ^, then there is a match if the remaining characters in the set are not present. 
^ Anchor the pattern to the beginning of the string. Only when first. 
$ Anchor the pattern to the end of the string. Only when last. 

Practical Programming in Tcl and Tk, 3rd Ed. © 1999, Brent Welch, Ch 11, p. 146を参照してください。

+1

別の参照ではサポートされていません。 –

関連する問題