You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,10 @@ You can purchase the book using these links:
20
20
21
21
*https://gumroad.com/l/js_regexp
22
22
*https://leanpub.com/js_regexp
23
-
* You can also get the book as part of **Awesome Regex** bundle from https://leanpub.com/b/regex or https://gumroad.com/l/regex
23
+
* You can also get the book as part of **Awesome Regex** bundle from https://gumroad.com/l/regex or https://leanpub.com/b/regex
24
24
* See https://learnbyexample.github.io/books/ for list of other books
25
25
26
-
For a preview of the book, see [sample chapters](https://github.com/learnbyexample/learn_js_regexp/blob/master/sample_chapters/js_regexp_sample_chapters.pdf)
26
+
For a preview of the book, see [sample chapters](https://github.com/learnbyexample/learn_js_regexp/blob/master/sample_chapters/js_regexp_sample.pdf)
27
27
28
28
The book can also be [viewed as a single markdown file in this repo](./js_regexp.md). See my blogpost on [generating pdf from markdown using pandoc](https://learnbyexample.github.io/tutorial/ebook-generation/customizing-pandoc/) if you are interested in the ebook creation process.
29
29
@@ -33,11 +33,11 @@ For web version of the book, visit https://learnbyexample.github.io/learn_js_reg
33
33
34
34
# Feedback
35
35
36
-
Please open an issue if you spot any typo/errors.
36
+
[Open an issue](https://github.com/learnbyexample/learn_js_regexp/issues) if you spot any typo/errors.
37
37
38
-
I'd also highly appreciate your feedback about the book.
38
+
:warning::warning: Please DO NOT submit pull requests. Main reason being any modification requires changes in multiple places.
*[MDN: Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) — documentation and examples
69
69
*[/r/learnjavascript/](https://www.reddit.com/r/learnjavascript/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
70
70
*[stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on JavaScript and regular expressions
71
-
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
71
+
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on [pandoc](https://github.com/jgm/pandoc/) and `tex` related questions
72
72
* Cover image: [LibreOffice Draw](https://www.libreoffice.org/discover/draw/) and [regulex](https://jex.im/regulex)
73
73
*[Warning](https://commons.wikimedia.org/wiki/File:Warning_icon.svg) and [Info](https://commons.wikimedia.org/wiki/File:Info_icon_002.svg) icons by [Amada44](https://commons.wikimedia.org/wiki/User:Amada44) under public domain
74
+
*[pngquant](https://pngquant.org/) and [svgcleaner](https://github.com/RazrFalcon/svgcleaner) for optimizing images
74
75
*[mdBook](https://github.com/rust-lang/mdBook) — for web version of the book
75
76
*[mdBook-pagetoc](https://github.com/JorelAli/mdBook-pagetoc) — for adding table of contents for each chapter
76
77
*[minify-html](https://github.com/wilsonzlin/minify-html) — for minifying html files
Copy file name to clipboardExpand all lines: Version_changes.md
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,13 @@
1
1
<br>
2
2
3
+
### 1.6
4
+
5
+
* Code snippets checked to work with Chrome/Chromium console version 89+
6
+
* Updated `escapeRegExp` function as per [MDN: Regular Expressions doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
Copy file name to clipboardExpand all lines: js_regexp.md
+16-21Lines changed: 16 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -10,29 +10,28 @@ A good understanding of basic-level programming concepts and prior experience wo
10
10
11
11
## Conventions
12
12
13
-
* The examples presented here have been tested on Chrome/Chromium console (version 81+) and includes features not available in other browsers and platforms.
13
+
* The examples presented here have been tested on Chrome/Chromium console (version 89+) and includes features not available in other browsers and platforms.
14
14
* Code snippets shown are copy pasted from the console and modified for presentation purposes. Some of the commands are preceded by comments to provide context and explanations. Blank lines have been added to improve readability and output is skipped when it is `undefined` or otherwise unnecessary to be shown.
15
15
* Unless otherwise noted, all examples and explanations are meant for *ASCII* characters.
16
16
* External links are provided for further reading throughout the book. Not necessary to immediately visit them. They have been chosen with care and would help, especially during rereads.
17
-
* The [learn_js_regexp](https://github.com/learnbyexample/learn_js_regexp) repo has all the code snippets and exercises and other details related to the book. Click the **Clone** button to get the files.
17
+
* The [learn_js_regexp](https://github.com/learnbyexample/learn_js_regexp) repo has all the code snippets, exercises and other details related to the book. Click the **Code** button to get the files.
18
18
19
19
## Acknowledgements
20
20
21
21
*[MDN: Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions) — documentation and examples
22
22
*[/r/learnjavascript/](https://www.reddit.com/r/learnjavascript/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
23
23
*[stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on JavaScript and regular expressions
24
-
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
24
+
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on [pandoc](https://github.com/jgm/pandoc/) and `tex` related questions
25
25
* Cover image: [LibreOffice Draw](https://www.libreoffice.org/discover/draw/) and [regulex](https://jex.im/regulex)
26
26
*[Warning](https://commons.wikimedia.org/wiki/File:Warning_icon.svg) and [Info](https://commons.wikimedia.org/wiki/File:Info_icon_002.svg) icons by [Amada44](https://commons.wikimedia.org/wiki/User:Amada44) under public domain
27
+
*[pngquant](https://pngquant.org/) and [svgcleaner](https://github.com/RazrFalcon/svgcleaner) for optimizing images
27
28
28
29
## Feedback and Errata
29
30
30
31
I would highly appreciate if you'd let me know how you felt about this book, it would help to improve this book as well as my future attempts. Also, please do let me know if you spot any error or typo.
@@ -53,7 +52,7 @@ Resources mentioned in Acknowledgements section above are available under origin
53
52
54
53
## Book version
55
54
56
-
1.5
55
+
1.6
57
56
58
57
See [Version_changes.md](https://github.com/learnbyexample/learn_js_regexp/blob/master/Version_changes.md) to track changes across book versions.
59
58
@@ -130,7 +129,7 @@ First up, a simple example to test whether a string is part of another string or
130
129
>sentence.includes('z')
131
130
<false
132
131
133
-
// check if 'sentence' matches the pattern as described by the regexp
132
+
// check if 'sentence' matches the pattern as described by the RegExp object
134
133
>/is/.test(sentence)
135
134
<true
136
135
>/z/.test(sentence)
@@ -194,7 +193,7 @@ Examples for `i` flag is shown below. `g` flag will be discussed in [replace met
194
193
195
194
## RegExp constructor and reuse
196
195
197
-
The RegExp object can be saved in a variable. This helps to improve code clarity, enable reuse, etc.
196
+
The RegExp object can be saved in a variable. This helps to improve code clarity, enables reuse, etc.
198
197
199
198
```js
200
199
>constpet=/dog/
@@ -225,7 +224,6 @@ The main advantage of the constructor over `//` literal is the ability to dynami
225
224
>constpat1=newRegExp(`${greeting} there`)
226
225
> pat1
227
226
</hi there/
228
-
229
227
>newRegExp(`${greeting.toUpperCase()} there`)
230
228
</HI there/
231
229
```
@@ -397,7 +395,7 @@ water 10`
397
395
398
396
# Anchors
399
397
400
-
In this chapter, you'll be learning about qualifying a pattern. Instead of matching anywhere in the given input string, restrictions can be specified. For now, you'll see the ones that are already part of regular expression features. In later chapters, you'll learn how to define your own rules for restriction.
398
+
In this chapter, you'll be learning about qualifying a pattern. Instead of matching anywhere in the given string, restrictions can be specified. For now, you'll see the ones that are already part of regexp features. In later chapters, you'll learn how to define your own rules for restriction.
401
399
402
400
These restrictions are made possible by assigning special meaning to certain characters and escape sequences. The characters with special meaning are known as **metacharacters** in regexp parlance. In case you need to match those characters literally, you need to escape them with a `\` character (discussed in [Escaping metacharacters](#escaping-metacharacters) chapter).
403
401
@@ -730,7 +728,6 @@ In a conditional expression, you can use the logical operators to combine multip
730
728
// replace either 'cat' at start of string or 'cat' at end of word
@@ -925,7 +922,7 @@ There are many things in the above regexp that you haven't learnt yet. They'll b
925
922
"f*(a^b) - 3*c"
926
923
```
927
924
928
-
> Note that the `/` delimiter character isn't escaped in the above function. Use `[.*+\-?^${}()|[\]\\\/]` to escape the delimiter as well.
925
+
> Note that the `/` delimiter character isn't escaped in the above function. Use `[.*+?^${}()|[\]\\\/]` to escape the delimiter as well.
929
926
930
927
## Dynamically building alternation
931
928
@@ -1286,7 +1283,6 @@ Next up, how to construct AND conditional using dot metacharacter and quantifier
1286
1283
// match 'Error' followed by zero or more characters followed by 'valid'
1287
1284
>/Error.*valid/.test('Error: not a valid input')
1288
1285
<true
1289
-
1290
1286
>/Error.*valid/.test('Error: key not found')
1291
1287
<false
1292
1288
```
@@ -2170,7 +2166,6 @@ As highlighted earlier, handle negative logic with care, as you might end up mat
2170
2166
// elements not containing vowel characters
2171
2167
>words.filter(w=>/^[^aeiou]+$/.test(w))
2172
2168
< ["tryst", "glyph", "why"]
2173
-
2174
2169
// easier to write and maintain, note the use of '!' operator
2175
2170
// but this'll match empty strings too unlike the previous solution
2176
2171
>words.filter(w=>!/[aeiou]/.test(w))
@@ -2610,6 +2605,7 @@ When backreferencing is not required, you can use a non-capturing group to avoid
2610
2605
// but using capture group will not give expected output
@@ -2877,7 +2873,7 @@ Make sure to test these patterns for your use case. For example, the below data
2877
2873
2878
2874
## Summary
2879
2875
2880
-
Some patterns are quite complex and not easy to build and validate from scratch. Libraries like **CommonRegexJS** are helpful to reduce your time and effort needed for commonly known tasks. However, you do need to **test** the solution for *your* use case. See also [stackoverflow: validating email addresses](https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression).
2876
+
Some patterns are quite complex and not easy to build and validate from scratch. Libraries like **CommonRegexJS** are helpful to reduce your time and effort needed for commonly known tasks. However, you do need to **test** the solution for *your* use case. See also [stackoverflow: validating email addresses](https://stackoverflow.com/q/201323/4082052).
2881
2877
2882
2878
# Lookarounds
2883
2879
@@ -2893,7 +2889,6 @@ Before you get used to lookarounds too much, it is good to remember that JavaScr
2893
2889
// filter elements containing digit and '#' characters
2894
2890
>items.filter(s=>/\d/.test(s) &&s.includes('#'))
2895
2891
< ["#foo 123"]
2896
-
2897
2892
// modify elements only if it doesn't start with '#'
@@ -2964,7 +2959,7 @@ In all the examples so far, lookahead grouping was placed as a suffix and lookbe
2964
2959
<"foo_baz = num1 + 35 * 42 / num2"
2965
2960
```
2966
2961
2967
-
> See [this stackoverflow Q&A](https://stackoverflow.com/questions/50011366/javascript-regex-negative-lookbehind-not-working-in-firefox) for a workaround if lookbehind isn't supported.
2962
+
> See [this stackoverflow Q&A](https://stackoverflow.com/q/50011366/4082052) for a workaround if lookbehind isn't supported.
2968
2963
2969
2964
## Positive lookarounds
2970
2965
@@ -3386,7 +3381,7 @@ You can also use codepoints inside `\u{}` construct to specify unicode character
3386
3381
< ["fox", "eagle"]
3387
3382
```
3388
3383
3389
-
> See also [stackoverflow: Unicode string to hex](https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex).
3384
+
> See also [stackoverflow: Unicode string to hex](https://stackoverflow.com/q/21647928/4082052).
3390
3385
3391
3386
## Cheatsheet and Summary
3392
3387
@@ -3447,7 +3442,7 @@ Note that some of these resources are not specific to JavaScript, so use them wi
3447
3442
* [Awesome Regex](https://github.com/aloisdg/awesome-regex) — curated collection of libraries, tools, frameworks and software
3448
3443
* [randexp.js](https://github.com/fent/randexp.js) — Generate strings that match a given regular expression
* [stackoverflow: Greedy vs Reluctant vs Possessive Quantifiers](https://stackoverflow.com/questions/5319840/greedy-vs-reluctant-vs-possessive-quantifiers)
3458
+
* [stackoverflow: Greedy vs Reluctant vs Possessive Quantifiers](https://stackoverflow.com/q/5319840/4082052)
3464
3459
* [cloudflare: Details of the Cloudflare outage on July 2, 2019](https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/) — see appendix for details about CPU exhaustion caused due to regular expression backtracking
0 commit comments