This is the 16th day of my participation in the August More Text Challenge

☆☆ Today’s content (regular in-depth study and work used in the regular method) focus!! Do do do

Can serve as a beginner’s learning route, can refer to, learning progress is not particularly driven! Ongoing update

Combined with their own understanding, simple and comprehensive summary of the basic knowledge points in the process of learning JavaScript in vernacular Chinese, easy to deepen understanding!

Let’s get started! ‘Only a firm foundation can build a tall building ‘! Come on! Take it seriously!

1, comb and review the knowledge points yesterday

  • offsetWidth / clientWidth / style.width
  • offsetLeft / offsetTop
  • Magnifying glass:onmouseover / out / move
  • Regular:\d      \w     \s     ^ $    .    ? -- {0, 1}      +--{1,}  -- {0} \ *        1 [35]     3 | 1 (5)          /^\w5$/

2. Regex implements form validation

  • Events needed:

    • onsubmit     为 formTag add event
    • onsubmitEvent handler, throughreturnCan now be submitted successfully by the user
  • Requires a button whose type value is submit

3. Correlation method in re

3.1 Regular expression related methods

.test() tests whether a string conforms to a regular specification, returning true if it does, false otherwise

3.2 usage:reg.test(str)

.exec() returns an array of length 1 based on the regular expression (array has only one value)

Usage: reg. The exec (STR);

Methods for replaying strings:

The.search(reg) method returns the position of the first substring that matches what the regular expression is looking for.

Usage: STR. Search (reg);

The.match() method uses the regular expression pattern to perform a lookup on a string and returns the results containing the lookup as an array.

Usage: STR. Match (reg)

Str.replace (Old string, new string)

.replace () is replaced by a regular expression and returns a new string

Usage: str.replace(regular expression, new string to replace) If you want to implement global replacement, add a modifier g to the regular expression

3.3 Regular expression method practice

  1. str = "good good study, day day up";

Replace good with best in the string

var reg = /good/g
str.replace(reg, 'best')
Copy the code
  1. str = "  hello  big  , hello  big beg bog bag bag   ";

Replace Bog beg bag Big with bug

var reg = /b(o|e|a|i)g/g; // 或者: /b[oeai]g/g
str.replace(reg, 'bug')
Copy the code
  1. Removes whitespace at the beginning of the string"   hello  world    "
     " hello world ".replace(/^\s+/."")
` `5. Remove whitespace at the end of the string` `js
     " hello world ".replace(/\s+$/."")
Copy the code
  1. Remove whitespace at the beginning and end of the string once
' hello world '.replace(/(^\s+)|(\s+$)/g.' ')
Copy the code
  1. Removes all whitespace characters from a string
' hello world '.replace(/\s+/g.' ')
Copy the code
  1. Var STR = "I am not 211 you 213 love 985 ";

Find the number in the string and store it in the array

var reg = /\d+/
var arr = str.match(reg)
Copy the code

Preview: Come on, dream chasers

[preview] : Next to learn cookie, will also know it will..

Learning is a continuous process, stick to it, there will be harvest!

Accumulate over a long period, consolidate the foundation, early into Dachang!

It’s not easy to keep it up, and it’s not easy to keep it up. You’re great!

Calm Down & Carry On!


Read more:

Review of previous updates

【 Relearn JS】 Learn every day to consolidate the foundation:

【day1】

[DAY2] Various operators,

[DAY3] Data type,

【day4】 Loop structure & Conditional statement,

【 DAY5 】 function (key),

【 DAY6 】 Scope & event

【day7】 Object & Array method summary,

[day8] String method & partial sort,

【 DAY9 】Math object & Encapsulation function,

【 DAY10 】BOM- Browser object model,

【 DAY11 】DOM- Document Object Model

【 DAY12 】Event First Knowledge of Event object (1)

【 DAY13 】Event First Knowledge of Event object (2)

【 DAY14 】 Event delegate & Drag principle

【 DAY15 】 Drag-and-drop implementation & regular introduction

More on the way… A long way to go ==-.. – = =