Alibabacloud.com offers a wide variety of articles about fuzzy string matching javascript, easily find your fuzzy string matching javascript information here online.
JavaScript is matching 3 methods, Match,exec,test. These methods are related to strings and RegExp objects, but the use of scenes is not the same, easy to confuse. Match is a method of a string that receives a RegExp object as a parameter, and the other is a method of the RegExp object that receives a string parameter.
Work encountered a problem, two string matching, required: Each string contains a maximum of *,? can be infinitely many
* Represents a string of any length, while? Represents a character
The request can prompt two conflicts
Copy Code code as follows:
Implement the code in
long as the returned groupings are not required to be captured plus?:9 varStr= ' 123ABC '; TenAlert (pattern.exec (str));Nested groupings1 var pattern=/(a? ( B? (c?))) /; // nesting groups, getting inside out 2 var str= ' abc '; 3 Alert (pattern.exec (str)); 4 // first step: a[0], the entire match to the string ABC 5 // Step Two: a[1], match the first group (a? ( B? (c?))), ABC6// Third step: a[2], matching
:" ^[0-9]+ (. [ 0-9]{2})? $ "can only enter a positive real number with 1-3 decimal places:" ^[0-9]+ (. [ 0-9]{1,3})? $ "can only enter a non-zero positive integer:" ^\+? [1-9] [0-9]*$] can only enter a non-zero negative integer: "^\-[1-9][0-9]*$ "can only enter characters of length 3:" ^. {3}$ "can only enter a string consisting of 26 English letters:" ^[a-za-z]+$ "can only enter a string consisting of 26
test string:
abcdefg
First attempt: found that there was no match for line breaks because. is a match for any character except newline (/n).
Second attempt:
Matching
1. Replace only the first
var result= testdata.replace (
2. Replaces all
var result= testdata.replace (/
G: Delegates can make global matches.
I: represents case-insensitive
The Replace function is used in the JavaScript substitution string, but it is very unpleasant to find that the function replaces the first character that was matched in the actual use, and in the PHP language, replace is a global match and is replaced. No way, careful study, found that there are other ways to achieve global matching and replacement.
(1) In fact,
Strings are the most data structure involved in programming, and the need to manipulate strings is almost ubiquitous. A regular expression is a powerful weapon used to match strings. It is designed to define a rule for a string in a descriptive language, and any string that conforms to the rule, we think it "matches".\dCan match a number‘00\d‘Can match‘007‘,‘\d\d\d‘Can match‘010‘\wCan match a letter or numb
① determine if a String conforms to a regular requirementPatt.test (String);② find a string that matches the regular substringPatt.exec (String);"Example" form submission:A. User name cannot be empty, only numbers and letters, 6-11-bitB.email cannot be empty and properly formattedDOCTYPE HTML>HTMLLang= "en">Head> Me
Regular expression pattern matching JavascriptSummary: Collects some commonly used regular expressions.Regular expressions are used for string processing, form validation, and so on, practical and efficient, but often not too sure to use, so it is always necessary to search the Internet. I've collected some commonly used expressions here for the purposes of my memo. This post will be updated at any time.
Detailed description of grouping matching for JavaScript regular expressions.
Group
The following regular expression can match the kidkid:
/kidkidkid/
Another more elegant method is:
/(kid){3}/
A small whole enclosed in parentheses is called grouping.
Candidates
A group can contain multiple candidate expressions separated by |:
var reg = /I love (him|her|it)/;reg.test('I love him') // true reg.test('I love
how JavaScript implements global matching and substitution
This article mainly introduces the JavaScript implementation of the global matching and replacement method summary, very simple and practical, the need for small partners can refer to.
The Replace function is used in the
on.Greedy: When a character after * matches the current character of S, it is assumed that the previous characters are matched, and then encountered * does not need to go back to the already matched * (only the nearest * is required).Based on this we need to write down the location of the nearest *, starting from here to backtrack.1 /**2 * @param {string} s3 * @param {string} p4 * @return {Boolean}5 */6 v
Gets the HTML content of the first matching element, which cannot be used in an XML document, but can be used in an XHTML document, and in an HTML document we can use the. html () method to get the contents of any element. If the selector matches more than one element, only the HTML content of the first matching element is fetched, equivalent to the innerHTML in JavaScr
This article is an introduction to the considerations when using Exec for regular expression global matching in Javascript.
Let's take a look at common usage:
Copy Code code as follows:
Next, look at the bizarre events in the global model:
Copy Code code as follows:
The second statement does not return the desired result, but instead returns NULL because:
In
Regular Expression MatchingImplement regular expression matching with support for ‘.‘ and ‘*‘ .‘.‘ Matches any single character. ' * ' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be:bool IsMatch (const char *s, const char *p) Some examples:ismatch ("AA", "a") →falsei
This article describes the considerations when using exec in Javascript for global matching of regular expressions.
Let's take a look at common usage:
Copy codeThe Code is as follows:
Next, let's take a look at the strange events in global mode:Copy codeThe Code is as follows:
The second statement does not return the expected result, but returns null because:In global mode, when exec () finds the text tha
Get the contents of all matching elements: The result is text that is combined with the text content contained by all matching elements, which is valid for both HTML and XML documents, equivalent to the innertext attribute in JavaScript, readable and writable, but unable to parse the HTML tag:If callback is passed in, this function returns a
This method is used to append content to each matching element, which is similar to the case where JavaScript executes the AppendChild method on the specified element and adds them to the document.The parameters are explained as follows:ContentContent to append to the targetfunction (index, HTML)Returns an HTML string that is appended to the inside of each
This article gives you a detailed introduction to the concept of JavaScript Regular Expression grouping and matching, as well as the specific usage methods, with examples attached. If you need it, you can refer to it.
Group
The following regular expression can match the kidkid:
/kidkidkid/
Another more elegant method is:
/(kid){3}/
A small whole enclosed in parentheses is called grouping.
Candidates
A
Regular Expression of javascript matching license plate number
Matching characters include:
Jing Z 12345-jing Z12345
ZF 12345-ZF12345
Temporary 12345 temporary 12345
Rules:
First Digit: Chinese character or second digit: letter or Chinese character. Third digit can be a space.
Followed by 5-7 letters or numbers
Final result:
$ Str = "Beijing time 12345 "
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.