Home >Web Front-end >JS Tutorial >What kind of regular expression can display highlight?
What kind of regular expression will I bring to you this time? can display highlight. How can I use regular expression to display highlight? What are the precautions for regular expression display highlight? The following is a practical case, let’s take a look.
When programmers write code, they must deal withstring and "query". There is something called a regular expression at the intersection of the two. If you use this guy well, you can improve your programming efficiency. If you don't use it well... you can learn it first.
Regarding the use of regular expressions, here is a simple example:var m = location.href.match(/(\w+:)\/{0,3}([^\/]+)(?:(\/[^\?#]*))?(?:(\?[^#]+|.+))?(?:(#.*))?/); var res = { protocol: m[1], host: m[2], path: m[3], search: m[4], hash: m[5] }; console.log(res);After holding it for a few minutes = =||, I also feel that this regular expression is not particularly easy to understand (it is red and black, it should be slightly Be clear). Some friends may not know what (?:content) means. There is also knowledge about grouping and foresight similar to (?!content) and (?=content). It is recommended to ask Brother Du and Gu Niang.
1. Small DEMO example of regular application
/*** @author barret lee* @date 2013-10-06* @email barret.china@gmail.com*/ //outer varvar a = "this id outer string"; //closurefunction b() { //inner var var a = "this is inner string"; var g = a.replace(/this is inner string/g, function() { return new Function("/*clousure*/this.a")(); }); /** * @description closure - regExp test * @author barret lee */ function c() { return { a: a, g: g } } return c;} var s = b()(); //s.a, s.gRegular matching, processing the above pile Small DEMO of string:
/*** @author barret lee* @date 2013-10-06* @email barret.china@gmail.com*/ //outer varvar a = "this id outer string"; //closurefunction b() { //inner var var a = "this is inner string"; var g = a.replace(/this is inner string/g, function() { return new Function("/*clousure*/this.a")(); }); /** * @description closure - regExp test * @author barret lee */ function c() { return { a: a, g: g } } return c;} var s = b()(); //s.a, s.gis similar to many regular expressions, which are quite convenient to use. of. Regular skills are worth having~ I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Related reading:
How to use jquery's ajax to asynchronously submit form data
How to implement springmvc to receive the array submitted by jquery Then extract the data
Detailed explanation of vue.js syntax and common instructions
The above is the detailed content of What kind of regular expression can display highlight?. For more information, please follow other related articles on the PHP Chinese website!