JavaScript 中匹配单个字符实例
2017-08-10 16:15
405 查看
通过正则表达式,匹配任意大写“L”实例:
代码如下:
代码如下:
<!DOCTYPE html> <html> <head> <title>test</title> <script> var myRegExp=/L/; function Validate(entry){ return myRegExp.test(entry); } function ShowPrompt(){ var entry=prompt("This script tests for matches for the regular expression pattern:"+myRegExp+".\nType in a string and clik on the OK button.","Type your text here."); if(Validate(entry)){ alert("There is a match!\n The regular expression pattern is:"+myRegExp+".\n"); }else{ alert("There is no match in the string you entrered.\n"+myRegExp+".\n The string that you entere was:'"+entry+"'."); } } </script> </head> <body> <form name="myFrom"> <button type="button" onclick="ShowPrompt()">Click here to enter text.</button> </form> </body> </html>
相关文章推荐
- 匹配字符JavaScript: The Definitive Guide 权威指南,读书笔记(二)
- SqlServer nvarchar中的中文字符匹配,更改SqlServer实例和数据库排序规则的办法
- Javascript正则表达式匹配中文字符
- Java实例1 - 朴素字符匹配 Brute Force
- 正则表达式教程之匹配单个字符详解
- [cnblogs镜像]JavaScript 字符串匹配 | JS 的正则用法 | 从后边匹配
- JPQL模糊匹配单个字符
- JavaScript lastIndexOf方法入门实例(计算指定字符在字符串中最后一次出现的位置)
- JavaScript indexOf方法入门实例(计算指定字符在字符串中首次出现的位置)
- JavaScript indexOf方法入门实例(计算指定字符在字符串中首次出现的位置)
- JavaScript charCodeAt方法入门实例(用于取得指定位置字符的Unicode编码)
- [正则表达式] 大小写字母和数字的字符匹配的实例
- javascript正则表达式之匹配任何字符和非贪婪匹配
- 基于proteus的51单片机仿真实例六十三、字符液晶LCD1602显示单个字符实例
- 一个JavaScript处理textarea中的字符成每一行实例
- Javascript匹配字符是中文还是英文
- 常用的javascript匹配正则表达式和实例
- JavaScript charCodeAt方法入门实例(用于取得指定位置字符的Unicode编码)
- 正则表达式(一)-- 匹配单个字符
- JavaScript字符串对象charAt方法入门实例(用于取得指定位置的字符)