Regular expression for matching Chinese characters: [u4e00-u9fa5]
Matching double-byte characters (including Chinese characters): [^x00-xff]
Application: counting characters The length of the string (the length of a double-byte character is counted as 2, and the length of an ASCII character is counted as 1)
Regular expression to match empty lines: [s| ]*
Match Regular expression for HTML tags: /<(.*)>.*>|<(.*) />/
Regular expression for matching leading and trailing spaces: (^ s*)|(s*$)
Application: There is no trim function like vbscript in JavaScript, we can use this expression to achieve it, as follows:
Use regular expressions to decompose and convert IP addresses:
The following is a javascript program that uses regular expressions to match IP addresses and convert IP addresses into corresponding values:
However, if the above program does not use regular expressions, it may be simpler to use the split function to decompose it directly. The program is as follows:
Matching email addresses Regular expression: w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
Regular expression matching URL: http: //([w-]+.)+[w-]+(/[w- ./?%&=]*)?
An algorithm for removing repeated characters from a string using regular expressions Program:
A javascript program that uses regular expressions to extract file names from URL addresses. The following result is page1
Use regular expressions to limit the input content of the text box in the web form:
Use regular expressions to limit the input to Chinese only:
Use regular expressions Limit the input of only full-width characters:
Use regular expressions to limit the input of numbers:
Use regular expressions Only numbers and English can be entered: