作者: pingaaa 時間: 2015-6-2 05:57 標題: javascript regular expressions一問
本帖最後由 pingaaa 於 2015-6-2 12:29 編輯
var patKeyValue = /"(.*)"\s*=\s*"(.*)"/; // "key" = "value";
var patCommentSingle = /\/\/(.*)/; // single line comment
var patCommentBlock = /\/\*(.*)\*\//; /* block comment on one line */
var patCommentStart = /\/\*(.*)/; /* block comment start */
var patCommentEnd = /(.*)\*\//; /* block comment end */]
想問下ching / / 中間既
(.*)
* 既意思
google 左好耐都唔明 幾個var 其實想做咩
thanks
作者: 7h1r733n 時間: 2015-6-2 06:47
本帖最後由 7h1r733n 於 2015-6-2 06:48 編輯
var patKeyValue = /"(.*)"\s*=\s*"(.*)"/; // "key" = "value";
var patCommentSingle = /\/\/(.*)/; // s ...
pingaaa 發表於 2015-6-2 05:57
http://www.w3schools.com/jsref/jsref_regexp_zeromore.asp
作者: wongfung 時間: 2015-6-2 17:07
本帖最後由 wongfung 於 2015-6-2 17:09 編輯
1.
. Matches any single character (many applications exclude newlines, and exactly which characters are considered newlines is flavor-, character-encoding-, and platform-specific, but it is safe to assume that the line feed character is included). Within POSIX bracket expressions, the dot character matches a literal dot. For example, a.c matches "abc", etc., but [a.c] matches only "a", ".", or "c".
2.
* Matches the preceding element zero or more times. For example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]* matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on. (ab)* matches "", "ab", "abab", "ababab", and so on.
作者: tunster 時間: 2015-6-2 17:19
var patKeyValue = /"(.*)"\s*=\s*"(.*)"/; // "key" = "value";
var patCommentSingle = /\/\/(.*)/; // s ...
pingaaa 發表於 2015-6-2 05:57
"." = 一個字元
"*" = 前面個字元可以出現多過 0 次
即係嗰個位有, 或者無字
作者: lkfo415579 時間: 2015-6-2 18:19
LL(1)compiler 講起都XX
作者: hxhsao 時間: 2015-6-4 12:54
*咪match所有野,樓主真係問呢樣咁簡單?
定係.*?
作者: KinChungE 時間: 2015-6-4 12:55
.係所有single character
.*先係match所有野
作者: hxhsao 時間: 2015-6-4 12:58
u are right
作者: hxhsao 時間: 2015-6-4 13:04
搭單一問,
.*\d
點解match hello123,而
.*\d*
match hello123world
作者: rabbit82047 時間: 2015-6-4 14:16
回覆 9# hxhsao
如果咁講可能容易D 明白
.*\d
Match any character ending with a digit
.*\d*
Match any character ending with any digit or not
* 係代表0至多次, 所以 .*\d* 基本上同 .* 係一樣
作者: DarkHero 時間: 2015-6-5 02:28
樓主係咪真係有用心去睇過?

不過regex 易學難精,唔用一排又會忘記晒
所以有人發明左語義版regex
作者: fhleung 時間: 2015-6-8 21:58
用邊一种 language 先?
perl, php, javascript ?
作者: fhleung 時間: 2015-6-9 09:37
- <script type="text/javascript">
- function validate() {
- var x = document.forms["myForm"]["photo"].value ;
- var y = x.length ;
- var extension = x.substr(y-3);
- alert("begining... "+extension );
- if ( x.match(/\./g) == null ) { alert("NO dot. type"); return false; }
- if ( x.match(/\./g).length > 1 ) { alert("error"); return false; }
- if ( x.match(/!/g) != null ) { alert("symbol ! "); return false; }
- if ( x.match(/\@/g) != null ) { alert("symbol @ "); return false; }
- if ( x.match(/\#/g) != null ) { alert("symbol # "); return false; }
- if ( x.match(/\$/g) != null ) { alert("symbol $ "); return false; }
- if ( x.match(/\%/g) != null ) { alert("symbol % "); return false; }
- if ( x.match(/\^/g) != null ) { alert("symbol ^ "); return false; }
- if ( x.match(/\&/g) != null ) { alert("symbol & "); return false; }
- if ( x.match(/\*/g) != null ) { alert("symbol * "); return false; }
- if ( x.match(/\(/g) != null ) { alert("symbol ( "); return false; }
- if ( x.match(/\)/g) != null ) { alert("symbol ) "); return false; }
- if ( x.match(/-/g) != null ) { alert("symbol - "); return false; }
- if ( y > 24 ) { alert("name too long " + y ); return false; }
- if ( extension == "jpg" ) { alert("check 2 "+extension);
- if ( x.match(/\./g).length == 1 ) { alert("symbol . "); return true; }}
- if ( extension == "png" ) { alert("check 2 ");
- if ( x.match(/\./g).length == 1 ) { alert("symbol . "); return true; }}
- if ( extension == "JPG" ) { alert("check 2 "); return true; }
- if ( extension == "PNG" ) { alert("check 2 "); return true; }
- if ( extension == "peg") { alert("check 2 "); return true; }
- alert("finally...");
- return false;
- }
- </script>
- http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_files
- <form name="myForm" onsubmit="return validate();" action="upload.cgi" enctype="multipart/form-data" method="post">
- <p><input name="photo" type="file" style="height:100px"/></p>
- <p><input name="Submit" type="submit" value="Submit UPLOADING" style="width:400px; height:200px"/></p> </form>

