Skip to content

Commit 65184ed

Browse files
committed
regexp draft
1 parent 1369332 commit 65184ed

File tree

11 files changed

+711
-380
lines changed

11 files changed

+711
-380
lines changed

5-regular-expressions/01-regexp-introduction/article.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,32 @@ There are only 5 of them in JavaScript:
9696
`m`
9797
: Multiline mode (covered in the chapter <info:regexp-multiline>).
9898
99+
`s`
100+
: "Dotall" mode, allows `.` to match newlines (covered in the chapter <info:regexp-character-classes>).
101+
99102
`u`
100103
: Enables full unicode support. The flag enables correct processing of surrogate pairs. More about that in the chapter <info:regexp-unicode>.
101104
102105
`y`
103106
: Sticky mode (covered in the [next chapter](info:regexp-methods#y-flag))
104107
108+
We'll cover all these flags further in the tutorial.
105109
106-
## The "i" flag
107-
108-
The simplest flag is `i`.
109-
110-
An example with it:
110+
For now, the simplest flag is `i`, here's an example:
111111
112112
```js run
113113
let str = "I love JavaScript!";
114114
115-
alert( str.search(/LOVE/) ); // -1 (not found)
116-
alert( str.search(/LOVE/i) ); // 2
117-
```
115+
alert( str.search(/LOVE/i) ); // 2 (found lowercased)
118116
119-
1. The first search returns `-1` (not found), because the search is case-sensitive by default.
120-
2. With the flag `pattern:/LOVE/i` the search found `match:love` at position 2.
117+
alert( str.search(/LOVE/) ); // -1 (nothing found without 'i' flag)
118+
```
121119
122120
So the `i` flag already makes regular expressions more powerful than a simple substring search. But there's so much more. We'll cover other flags and features in the next chapters.
123121
124122
125123
## Summary
126124
127-
- A regular expression consists of a pattern and optional flags: `g`, `i`, `m`, `u`, `y`.
125+
- A regular expression consists of a pattern and optional flags: `g`, `i`, `m`, `u`, `s`, `y`.
128126
- Without flags and special symbols that we'll study later, the search by a regexp is the same as a substring search.
129-
- The method `str.search(regexp)` returns the index where the match is found or `-1` if there's no match.
127+
- The method `str.search(regexp)` returns the index where the match is found or `-1` if there's no match. In the next chapter we'll see other methods.

0 commit comments

Comments
 (0)