1
我的正則表達式模式必須以/ *開始並且必須以* /結尾;在它之間它可能包含所有字母,數字,特殊字符 - 零次或多次。使用預定義的開始和結束模式的正則表達式
我已經做了以下的正則表達式表達了這一點:
[/*][[email protected]#\^\$&\*\(\)-_\+=\[\]\{\}\|\\,\.\?\s]*[*/;]
但這種表達不顯示模式,如錯誤:
- /*
- /* sdfsdff
- /* sdfsfeff *
- /* fefef3323 */
這是錯誤的。它必須以/ *開頭並以* /結尾;不惜任何代價。
以下是用於測試此模式的角碼。請有人幫忙!
CODE:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-messages.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<form name="form1" novalidate>
{{form1.age.$error}}
<input type="text" name="age" ng-model="myAge" ng-pattern="/^[/*][[email protected]#\^\$&\*\(\)-_\+=\[\]\{\}\|\\,\.\?\s]*[*/;]$/" />
<div ng-messages="form1.age.$error" >
<span ng-message="pattern">This field has wrong pattern.</span>
</div>
</form>
<script>
//module declaration
var app = angular.module("myApp",['ngMessages']);
//controller declaration
app.controller('myCtrl',function($scope){
//code goes here ...
});
</script>
</body>
</html>
參考:
Regular expression include and exclude special characters
http://www.regular-expressions.info/repeat.html
從開始和結束中刪除字符類 – rock321987
'[/] [*] [a-zA-Z0-9〜@#\^\ $ \ \ * \(\)-_ \ + = \ [\] {\} \ | \\,\。\?\ s] * [*] [/] [;]' – rock321987
嘗試http:// regexr。COM /爲您的正則表達式 – NatureShade