Web.js. string and regular expressions

VAR STR = ‘Abcdef’; Alert (Str.Substring (2, 5)); // CDE is not Includes end position Alert (Str.Substring (1)); // bcdef1
   

VAR STR = ‘A * B * CD * EF’; Alert (Str.Split (‘*’)); // Split Character 1

   
VAR STR = ‘Acef’; Alert (Str.Search (‘A’)); // 0 Find Character position Alert (Str.Search (‘f’)); // 3 alert (Str.Search (‘CE’)); // 1 alert (Str.Search (‘o’)); // – 1 match failed Then -1

regular

VAR RE = New Regexp (‘b’, ‘i’); // i does not consider the case // or var = / b / i; var str = ‘abcdef’; // convert B to b The same result, if you remove i, you can’t do Alert (STR
   1. Match 

VAR STR = ‘ ASDF 34 656 CVS33 ‘; var RE = / \ d / g;Alert (Str.Match (re)); // 3, 4, 6, 5, 6, 3, 3match Get matching item 1Var str = ‘ASDF 34 656 CVS33’; var RE = / \ D + / g; // Global match: g – Global, + represents once or multiple Alert (Str.Match (re)); // 34, 656, 33

  2 .replace  
VAR STR = ‘ASDF 34 656 CVS33’; var RE = / \ D + / g; var RE2 = / \ D / g; Alert Str.Replace (RE, ‘*’)); // ASDF * * CVS *; ALERT (Str.Replace (RE2, ‘*’)); // ASDF ** *** CVS ** 1

   
Var str = ‘Henan, a villager Kaifeng haha’ Var Re = / Henan Kaifeng / g; // Remove the sensitive word Henan or Kaifeng VAR RE1 = / Henan | Kaifeng /; Alert (str.replace (RE, ‘*’)); Alert (Str.Replace (RE1, ‘*’)) / / Nothing to get off, try the result 1

3. [] Any character, range

[ABC]
 Example: o [USB] T - OBT, OST, OUT   [AZ], [0-9] 
Example: ID [0 -9] – ID0, ID5

[^ a] (all things outside)

Example: O [^ 0-9] T – oat, o? T, OT
 combination   
[A-Z0-9A-Z]
The above is the web.js that is introduced to you. The string is operated with the regular expression, I hope to help everyone. If you have any questions, please send you all the time, Xiaobian will reply to everyone!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment