JScript usage explain regular expressions, Sec.

Related Tags:

  Oh, a few first wordy last year done with C # Syntax highlighted a small thing, according to the information in the preparation of the document by the code into html format, so that it can show on the website and editor in the same syntax Elements highlighted the effectiveness of the code as well as support folding.    Exactly, this is the garden and on the blog you see similar.    Because I was using the MSN Space, it did not provide this feature, had no choice but to write a 1,10. 

  I use C # is prepared to initially use the super red tape for, while, switch, the Basic sentence if judged keyword, and so on, we MO joke, I was stupid do not know what is the expression of, You can only use this soil solution, of course, there is still soil to the effect of, but a function in the lengthy code, to protect the future it will probably be very difficult, I thought other software so it is impossible to write the bar, then between the google search for a while to find something to highlight the code and syntax open source projects, open up a look.    .    .    .    .    Halo, and one is so complicated that I really do not like to do is to see others code, I am not conceited, I see others code is really dizzy, unless there is a very detailed description of the document, otherwise I Aiming not want to see the two, the most is to see how others write interface, and then speculate on how he realized internal. 

  Although the search for the little things help, but still let me know that the regular expression Dongdong, see where specific forget it.    At that time, started on the side of a regular expression side of the duality of "breaking stuff."    Then not long blog Park re-opened in Bo, and the use of blog Park finally opened the syntax and function-you, then write their own HTML code highlight of the NEE lost one of the major driving forces.    Secondly, to do with C # syntax highlighting modules, running on the server side only, or WinForm procedure, and I get to the final is to show HTML code on the page, I think that is most suitable for the client script of this work .    Unfortunately, not very own JS understanding.    .    .    Later, during this period of time and Hugaoxiagao to the other, that did not improve the grammar module-plus. 

  Yesterday evening overtime overtime back home, had intended to continue to learn the UML see mode, but think the company has a module needs to be released from the database returns the results of all the HTML tags, I will open the regular expression tools RegexBuddy.    RegexBuddy results with the help of a document to see the use of a regular expression JScript simple teaching, and therefore have seized curiosity, opened UltraEdit-32 began to write a simple test to JavaScript. 

  My test here is not to repeat more than nonsense, because many places around the trial and many detours, here are directly summed up JScript test is the use of the Chiang Kai-shek. 

  Nonsense finished, the following entry is that! 

  Prime Minister talk about the Regular Expression JScript object RegExp. 

  JScript is provided in the expression of the class of RegExp operation can be used in two ways examples of RegExp type of object. 

  One method, constructor function of examples: 

  Var myRegex = new RegExp ( "\ \ w," "igm"); 
  / / \ W is the practical expression of the attention of a \ for the purpose of escaping, igm that were overlooked case, global search, multi-line search, will explain the method behind the direct assignment of: 

  Var myRegex = / \ w / igm; 
  / / Effect and a statement, here is no need to transfer characters, the original What is a regular expression is what looks like, and on the front igm igm examples of what specific role the same way we like to see, personally think that the first two kinds of methods are written in a relatively good read more, RegexBuddy help document also recommended a second way.    RegExp object contains the following actions: 

  Exec (string str): The Executive is the regular expression matching, and returned to the match result, according to the MSDN examples of the results is given, exec each implementation is a direct match from the end of the last position, and appears to be the return of value RerExp object, and the explanation given is RegexBuddy return an array, but did not give detailed examples, I think that is based on the results of tests under more reliable. 

  Compile (string regex, string flags): pre-compiler is the regular expression to make it run faster, tested efficiency is pre-compiled after marked improvement.    Regex parameters for a regular expression, the following flags can be a combination of three values: g - global search, my test results are not the only signs g match with the conditions of a string i - Ignore case m -- Multi-line search, it seems that the default is a multi-line search 

  Test (string str): If str match a regular expression returns true or false return, the object of similar string match method 

  RegExp object contains the following properties: 

  Index: string in the first match of the expression location, the initial -1 
  Input: a regular expression matching goal, the attention is read-only 
  LastIndex: The expression of the location of a match, it is the original (Returns the character Position where the next match begins in a searched string.) Do not know no translation wrong, I have not used this property. 
  LastMatch: Finally a matching string expression 
  LastParen: The last match of a match in the series, for example, the regular expression in a number of the () packet matches, lastParen said that the final group match result 
  LeftContext: from the beginning to string goals last match of the initial position of all characters. 
  RightContext: from the end of last match position to the end of the target location of the string all characters. 
  $ 1… $ 9: n said that the first group match result, in a regular expression, there are a number of () packet useful when 

  Next talk about, JScript String object in a regular expression with the operational: 

  Match (string regex): accept a regular expression, and returns the string with the expression of this match. 
  Replace (srting regex, string str): with the regular expression match in the replacement string for str, this function seems simple, but there are also more advanced usage Oh, see the following examples. 
  Example 1: 

  Var str1 = "A: My name is Peter! \ NB: Hi Peter!"; 
  Str1 = str1.replace (/ Peter / g, "Jack"); 
  Alert (str1); 
  This example is very simple to string replacement, and this expression is not only the power of this course, if you use the skilled, but also use it a lot the past, a large number code needs to be done.    For example, in the code before and after the keywords highlighted as the HTML tags.    From the front, it would seem that the example only to replace the matching text replaced by the new text ah, how its use before and after insertion in the keyword tags?    Up to the imagination, if the replacement can use matches, then things do not will be easy to handle, as long as the replacement for the keyword: label is not the end of the first keyword tag on the trip. 

  But how to replace the use of a regular expression matching results? 

  At this time we need to use "matching variables," and matching variable that is a match for the results, the following is the matching variables: 
  $ & - That all matching group match result, and finally running Suo a matching group is a regular expression () packet 
  $ $ - $ Characters that, because of the matching variables spent $ characters, so it is necessary to escape 
  $ N - similar to the previous $ 1… $ 9, n said that the first group match result 
  $ Nn - is a very simple first group match result nn 
  $ `- Is the leftContext mentioned earlier, such as abcdefg be matched to the d abc then it is a leftContext 
  $ '- And very close to not comply with the above wrong!    This is rightContext, so as efg above example is the rightContext so now we have to be inserted before and after the keyword tags very simple: 

  Var str1 = "A: My name is Peter! \ NB: Hi Peter!"; 
  Str1 = str1.replace (/ Peter / g, "<b> $ & </ b>"); 
  Alert (str1); 
  Have a 0:39.    .    .    Wrote on it here. 

  Is the tool software download (Password: regex): regex buddy 2.06.zip 
  See example, I wrote: Grammar and JScript do-display (code streamlining) 

  MSDN contains is copied to a number of examples: 

  Function matchDemo () 
  ( 
  Var s; 
  Var re = new RegExp ( "d (b) (d)," "ig"); 
  Var str = "cdbBdbsbdbdz"; 
  Var arr = re.exec (str); 
  S = "$ 1 contains:" RegExp. $ 1 "\ n"; 
  S = "$ 2 contains:" RegExp. $ 2 "\ n"; 
  S = "$ 3 contains:" RegExp. $ 3; 
  Return (s); 
  ) 
  Function RegExpTest () 
  ( 
  Var ver = Number (ScriptEngineMajorVersion () "." ScriptEngineMinorVersion ()) 
  If (ver> = 5.5) ( 
  Var src = "The rain in Spain falls mainly in the plain."; 
  Var re = / \ w / g; 
  Var arr; 
  While ((arr = re.exec (src))! = Null) 
  Print (arr.index "-" arr.lastIndex "\ t" arr); 
  ) 
  Else ( 
  Alert ( "You need a newer version of JScript for this to work"); 
  ) 
  ) 

  Function matchDemo () 
  ( 
  Var s; / / Declare variable. 
  Var re = new RegExp ( "d (b) (d)," "ig"); / / Regular expression pattern. 
  Var str = "cdbBdbsbdbdz" / / String to be searched. 
  Var arr = re.exec (str); / / Perform the search. 
  S = "$ 1 returns:" RegExp. $ 1 "\ n"; 
  S = "$ 2 returns:" RegExp. $ 2 "\ n"; 
  S = "$ 3 returns:" RegExp. $ 3 "\ n"; 
  S = "input returns:" RegExp.input "\ n"; 
  S = "lastMatch returns:" RegExp.lastMatch "\ n"; 
  S = "leftContext returns:" RegExp.leftContext "\ n"; 
  S = "rightContext returns:" RegExp.rightContext "\ n"; 
  S = "lastParen returns:" RegExp.lastParen "\ n"; 
  Return (s) / / Return results. 
  ) 
  Document.write (matchDemo ()); 

  If you pass by the Daxia what is the view of this welcome here, we learn together, and common progress. 

Related articles:

Step by step teach you edit the registry and INF JS
  / Xiao Jun    JScript small Knowledge: JScript is an explanation of the type, object-based scripting language.    Although this mature and C object-oriented language than JScript function to some weak, but it is expected purposes, JScript have plenty of features larger.&...
List of CSS Tools CSS tools Recommended List
  Fonts    CSS Font and Text Style Wizard    Use this wizard to experiment with font and text styles and generate sample CSS style source code.    Em Calculator    Tool for calculating pixel font sizes to ems.    Korhoen typeviewer  &...
Blog usability: 10 design mistakes
  Author: Jakob Nielsen    Original Address: Jakob Nielsen - Weblog Usability: The Top Ten Design Mistakes    Blog is a website form, the site of a number of easy-to-use guidelines apply equally to blog, but the blog is a special type of Web site, some of their unique cha...
A random number of non-repetition method (a Zhezhao examples)
  0-99 of the order of a few, not repeat it here.    Apply to so many random box Zhezhao picture and in the broadcast animation stochastic music, but does not repeat. Methods such as a:    Oldtime = getTimer ();    My_array = new Array ();    N = 100;...
10 domain name selection skills
  Domain name is connected enterprises and Internet web site link, as its brand has the same important role in the identification, access corporate website visitors is the "key" that enterprise networks in the signs marking sites and charged with the site-oriented enterprises The dual...