From a2fca6709f878d39b42cfbcf2953ab281248081c Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Mon, 17 Sep 2018 21:46:53 -0500 Subject: [PATCH 1/9] initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2327a5ae..a44df9a5 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,4 @@ ## Project * [State machines and regexes](projects/state-mach-regex) + From a65eac41c69f35e0cd8fb819d047c334eb108076 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Tue, 18 Sep 2018 21:54:57 -0500 Subject: [PATCH 2/9] solve "12 monkeys" regex problem --- objectives/regex/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/objectives/regex/README.md b/objectives/regex/README.md index 365546c7..88b4de06 100644 --- a/objectives/regex/README.md +++ b/objectives/regex/README.md @@ -169,6 +169,18 @@ Write a regex that matches any one or two digit number, followed by a space, followed by the word `monkey`, followed by 0 or 1 `s`s. +#### Answer + +``` js +let regex = /^\d{1,2}\smonkeys?$/ + +regex.test('12 monkeys') // true +regex.test('1 monkey') // true +regex.test('123 monkeys') // false +regex.test('12 monkeyss') // false +regex.test('there are 12 monkeys') // false +``` + ### Convert Regex to State Machine Diagram Draw a state machine diagram for the following regex that matches a clock time. From ce843a793f7d0f38ed04fb6653d4b2c583673b35 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 12:12:30 -0500 Subject: [PATCH 3/9] readfile for stackoverflow regex --- .../extractlinks/extractlinks.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/projects/state-mach-regex/extractlinks/extractlinks.js b/projects/state-mach-regex/extractlinks/extractlinks.js index 99d583ec..810712fc 100644 --- a/projects/state-mach-regex/extractlinks/extractlinks.js +++ b/projects/state-mach-regex/extractlinks/extractlinks.js @@ -1,17 +1,20 @@ -const fs = require('fs'); +const fs = require('fs') -const args = process.argv.slice(2); +const readfile = path => + fs.readFile(path, 'utf-8', (err, data) => data) + +const args = process.argv.slice(2) if (args.length != 1) { - console.error("usage: extractlinks inputfile"); - process.exit(1); + console.error("usage: extractlinks inputfile") + process.exit(1) } -const filename = args[0]; +const filename = args[0] -// !!!! IMPLEMENT ME +let text = fs.readFile(filename, 'utf-8', (err, data) => data) -// Read file +console.log(text) // Set up regex From 37d3b15e69cc6b288f8a61cbcb15c6a6076bcc32 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 12:34:14 -0500 Subject: [PATCH 4/9] working on getting regex working, not all tests passing yet --- .../extractlinks/extractlinks.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/projects/state-mach-regex/extractlinks/extractlinks.js b/projects/state-mach-regex/extractlinks/extractlinks.js index 810712fc..97f299d1 100644 --- a/projects/state-mach-regex/extractlinks/extractlinks.js +++ b/projects/state-mach-regex/extractlinks/extractlinks.js @@ -12,9 +12,21 @@ if (args.length != 1) { const filename = args[0] -let text = fs.readFile(filename, 'utf-8', (err, data) => data) +const regex = /http[s]?:\/\/[\w.]+(.com|.net)/g -console.log(text) +fs.readFile(filename, 'utf-8', (err, data) => { + +}) + +console.log('https://google.com', '\n', regex.test('https://google.com')) +console.log('http://google.com', '\n', regex.test('http://google.com')) +console.log('https://www.google.com', '\n', regex.test('https://www.google.com')) +console.log('http://www.google.com', '\n', regex.test('http://www.google.com')) +console.log('https://www.google.net', '\n', regex.test('https://www.google.net')) +console.log('https://www.google', '\n', regex.test('https://www.google')) +console.log('https://www.google', '\n', regex.test('https://www.google')) + +console.log('https://this.that.google.com', '\n', regex.test('https://this.that.google.com')) // Set up regex From fb3cbbc7cbb6a9a25f2045d6e105b1511a634558 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 12:41:19 -0500 Subject: [PATCH 5/9] correctly logging urls from html file; need to tweak regex still --- .../extractlinks/extractlinks.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/projects/state-mach-regex/extractlinks/extractlinks.js b/projects/state-mach-regex/extractlinks/extractlinks.js index 97f299d1..e7999dc9 100644 --- a/projects/state-mach-regex/extractlinks/extractlinks.js +++ b/projects/state-mach-regex/extractlinks/extractlinks.js @@ -14,19 +14,17 @@ const filename = args[0] const regex = /http[s]?:\/\/[\w.]+(.com|.net)/g -fs.readFile(filename, 'utf-8', (err, data) => { - -}) - -console.log('https://google.com', '\n', regex.test('https://google.com')) -console.log('http://google.com', '\n', regex.test('http://google.com')) -console.log('https://www.google.com', '\n', regex.test('https://www.google.com')) -console.log('http://www.google.com', '\n', regex.test('http://www.google.com')) -console.log('https://www.google.net', '\n', regex.test('https://www.google.net')) -console.log('https://www.google', '\n', regex.test('https://www.google')) -console.log('https://www.google', '\n', regex.test('https://www.google')) - -console.log('https://this.that.google.com', '\n', regex.test('https://this.that.google.com')) +fs.readFile(filename, 'utf-8', (err, data) => console.log(data.match(regex))) + +//console.log('https://google.com', '\n', regex.test('https://google.com')) +//console.log('http://google.com', '\n', regex.test('http://google.com')) +//console.log('https://www.google.com', '\n', regex.test('https://www.google.com')) +//console.log('http://www.google.com', '\n', regex.test('http://www.google.com')) +//console.log('https://www.google.net', '\n', regex.test('https://www.google.net')) +//console.log('https://www.google', '\n', regex.test('https://www.google')) +//console.log('https://www.google', '\n', regex.test('https://www.google')) +// +//console.log('https://this.that.google.com', '\n', regex.test('https://this.that.google.com')) // Set up regex From acf5e792f13fe52b537124bb60db8a7dfdc12c25 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 21:16:58 -0500 Subject: [PATCH 6/9] complete url regex assignment; write solution as stream to urls.txt --- .../extractlinks/extractlinks.js | 40 +- .../extractlinks/stackoverflow.html | 3072 +++++++++-------- .../state-mach-regex/extractlinks/urls.txt | 177 + 3 files changed, 1783 insertions(+), 1506 deletions(-) create mode 100644 projects/state-mach-regex/extractlinks/urls.txt diff --git a/projects/state-mach-regex/extractlinks/extractlinks.js b/projects/state-mach-regex/extractlinks/extractlinks.js index e7999dc9..7665656a 100644 --- a/projects/state-mach-regex/extractlinks/extractlinks.js +++ b/projects/state-mach-regex/extractlinks/extractlinks.js @@ -1,33 +1,27 @@ -const fs = require('fs') +let fs = require('fs') -const readfile = path => - fs.readFile(path, 'utf-8', (err, data) => data) +let readfile = path => fs.readFile(path, 'utf-8', (err, data) => data) -const args = process.argv.slice(2) +let args = process.argv.slice(2) if (args.length != 1) { - console.error("usage: extractlinks inputfile") - process.exit(1) + console.error("usage: extractlinks inputfile") + process.exit(1) } -const filename = args[0] +let filename = args[0] +let regex = /https?:\/\/?[\w.-]+(com|net|org|blog)[\/[\w-]*]*[(?|&)\w+=\w+]*/g -const regex = /http[s]?:\/\/[\w.]+(.com|.net)/g +let readFile = fs.readFileSync(filename, 'utf8', (err, data) => data) +let urls = readFile.match(regex) -fs.readFile(filename, 'utf-8', (err, data) => console.log(data.match(regex))) +// Log array of URLs: +console.log(urls) -//console.log('https://google.com', '\n', regex.test('https://google.com')) -//console.log('http://google.com', '\n', regex.test('http://google.com')) -//console.log('https://www.google.com', '\n', regex.test('https://www.google.com')) -//console.log('http://www.google.com', '\n', regex.test('http://www.google.com')) -//console.log('https://www.google.net', '\n', regex.test('https://www.google.net')) -//console.log('https://www.google', '\n', regex.test('https://www.google')) -//console.log('https://www.google', '\n', regex.test('https://www.google')) -// -//console.log('https://this.that.google.com', '\n', regex.test('https://this.that.google.com')) +// Write each URL as a line to urls.txt +let outputFile = 'urls.txt' +let file = fs.createWriteStream(outputFile) +file.on('error', () => {}) +urls.forEach(url => file.write(url + '\n')) +file.end() -// Set up regex - -// Find matches - -// Print all matches diff --git a/projects/state-mach-regex/extractlinks/stackoverflow.html b/projects/state-mach-regex/extractlinks/stackoverflow.html index 64b1b30f..414fbaf5 100644 --- a/projects/state-mach-regex/extractlinks/stackoverflow.html +++ b/projects/state-mach-regex/extractlinks/stackoverflow.html @@ -1,5 +1,7 @@ - + + + @@ -8,19 +10,23 @@ + - + + - + - + + + @@ -28,94 +34,82 @@ - - - - - - +
- - - - -
- -
- - - - - - + + + + + + + + + + + + + + + + +
+
+
+

Learn, Share, Build

+

Each month, over 50 million developers come to Stack Overflow to learn, share their knowledge, and build their careers.

+

Join the world’s largest developer community.

+ Sign Up + +
+ +
+
- Stack Overflow Business Solutions: Looking to understand, engage, or hire developers? Learn more » + Stack Overflow Business Solutions: Looking to understand, engage, or hire developers? Learn more »
- + + +
+ + + + + +
+ + + +
-
+
+ -
-

+ + + -
+ +
-
+ id="question-summary-52435341"> +
0
votes
@@ -446,57 +536,57 @@

answers

-
1
-
view
+
6
+
views
-
+ id="question-summary-42640820"> +
-
0
+
12
votes
-
-
0
+
+
2
answers
-
1
-
view
+
857
+
views
-
+ id="question-summary-52435569"> +
0
votes
@@ -506,177 +596,177 @@

answers

-
9
+
2
views
-
+ id="question-summary-52417657"> +
-
-3
+
0
votes
-
-
2
+
+
0
answers
-
22
+
12
views
-
+ id="question-summary-52435309"> +
-
1
-
vote
+
2
+
votes
1
answer
-
16
+
11
views
-
+ id="question-summary-52435567"> +
-
1
-
vote
+
0
+
votes
0
answers
-
26
+
3
views
-
+ id="question-summary-52410301"> +
-
2
-
votes
+
1
+
vote
1
answer
-
27
+
8
views
-
+ id="question-summary-52435340"> +
-
0
-
votes
+
1
+
vote
-
-
1
-
answer
+
+
0
+
answers
-
4
+
12
views
-
+ id="question-summary-52435563"> +
0
votes
@@ -686,57 +776,57 @@

-
5
+
2
views

-
+ id="question-summary-52367607"> +
0
votes
-
-
0
+
+
3
answers
-
5
+
32
views
-
+ id="question-summary-52435562"> +
0
votes
@@ -746,27 +836,27 @@

-
17
+
4
views

-
+ id="question-summary-52435559"> +
0
votes
@@ -776,117 +866,117 @@

-
17
+
2
views

-
+ id="question-summary-52428463"> +
-
-2
+
2
votes
-
2
-
answers
+
1
+
answer
-
22
+
26
views
-
+ id="question-summary-52435558"> +
-
1
-
vote
+
0
+
votes
0
answers
-
10
+
3
views
-
+ id="question-summary-52435555"> +
-
1
-
vote
+
0
+
votes
0
answers
-
5
+
7
views
-
+ id="question-summary-52435329"> +
0
votes
@@ -896,27 +986,27 @@

answers

-
15
+
12
views
-
+ id="question-summary-52435550"> +
0
votes
@@ -926,27 +1016,27 @@

-
10
+
5
views

-
+ id="question-summary-52435274"> +
0
votes
@@ -956,34 +1046,34 @@

-
9
+
6
views

-
+ id="question-summary-52408860"> +
0
votes
-
-
0
-
answers
+
+
1
+
answer
-
+ id="question-summary-52435353"> +
-
1
-
vote
+
0
+
votes
0
answers
-
9
+
8
views
-
+ id="question-summary-52435545"> +
-
1
-
vote
+
0
+
votes
0
answers
-
15
+
3
views
-
+ id="question-summary-52435544"> +
-
1
-
vote
+
0
+
votes
0
answers
-
6
+
4
views
-
+ id="question-summary-42918231"> +
0
votes
-
-
0
+
+
2
answers
-
13
+
197
views
-
+ id="question-summary-52435542"> +
0
votes
@@ -1136,117 +1226,117 @@

-
7
+
4
views

-
+ id="question-summary-52435391"> +
-
-1
+
2
votes
-
-
0
-
answers
+
+
1
+
answer
-
7
+
20
views
-
+ id="question-summary-52435330"> +
-
0
-
votes
+
1
+
vote
-
-
0
-
answers
+
+
1
+
answer
-
12
+
13
views
-
+ id="question-summary-52415821"> +
-
0
+
3
votes
-
-
0
-
answers
+
+
1
+
answer
-
6
+
37
views
-
+ id="question-summary-52435536"> +
0
votes
@@ -1256,87 +1346,87 @@

-
6
+
4
views

-
+ id="question-summary-52435532"> +
-
1
-
vote
+
0
+
votes
-
-
1
-
answer
+
+
0
+
answers
-
8
+
7
views
-
+ id="question-summary-52435531"> +
0
votes
-
-
1
-
answer
+
+
0
+
answers
-
19
+
8
views
-
+ id="question-summary-52435530"> +
0
votes
@@ -1346,57 +1436,57 @@

-
11
+
5
views

-
+ id="question-summary-52435524"> +
-
1
-
vote
+
0
+
votes
0
answers
-
6
+
4
views
-
+ id="question-summary-52435495"> +
0
votes
@@ -1406,27 +1496,27 @@

-
3
+
10
views

-
+ id="question-summary-52435520"> +
0
votes
@@ -1436,27 +1526,27 @@

-
4
+
6
views

-
+ id="question-summary-52435519"> +
0
votes
@@ -1466,27 +1556,27 @@

answers

-
10
+
2
views
-
+ id="question-summary-52435518"> +
-
+ id="question-summary-51976380"> +
1
vote
@@ -1526,27 +1616,27 @@

-
9
+
23
views

-
+ id="question-summary-52435514"> +
0
votes
@@ -1556,57 +1646,57 @@

-
6
+
3
views

-
+ id="question-summary-52435070"> +
0
votes
-
-
0
+
+
2
answers
-
5
+
18
views
- - -
-
-
-
0
-
votes
-
-
-
1
-
answer
-
-
-
36
+
6
views
-
+ id="question-summary-52435510"> +
0
votes
@@ -1676,27 +1736,27 @@

answers

-
11
+
9
views
-
+ id="question-summary-52424029"> +
-1
votes
@@ -1706,27 +1766,27 @@

-
24
+
25
views

-
+ id="question-summary-52435507"> +
0
votes
@@ -1736,89 +1796,89 @@

answers

-
11
+
5
views
-
+ id="question-summary-52435168"> +
0
votes
-
-
0
+
+
3
answers
-
5
+
36
views
-
+ id="question-summary-52435459"> +
-
1
-
vote
+
0
+
votes
0
answers
-
14
+
8
views
-
+ id="question-summary-52435503"> +
-
2
+
0
votes
@@ -1826,27 +1886,27 @@

-
15
+
6
views

-
+ id="question-summary-52435500"> +
0
votes
@@ -1856,27 +1916,27 @@

-
10
+
3
views

-
+ id="question-summary-52435499"> +
0
votes
@@ -1886,27 +1946,27 @@

-
5
+
9
views

-
+ id="question-summary-52432379"> +
0
votes
@@ -1916,29 +1976,29 @@

answers

-
12
+
20
views
-
+ id="question-summary-52435498"> +
-
-1
+
0
votes
@@ -1946,57 +2006,57 @@

-
5
+
4
views

-
+ id="question-summary-52434088"> +
-
2
-
votes
+
1
+
vote
-
-
1
-
answer
+
+
0
+
answers
-
19
+
14
views
-
+ id="question-summary-52435494"> +
0
votes
@@ -2006,27 +2066,27 @@

-
6
+
4
views

-
+ id="question-summary-52435331"> +
-
+ id="question-summary-52435493"> +
0
votes
@@ -2066,27 +2126,27 @@

answers

-
6
+
3
views
-
+ id="question-summary-52435492"> +
0
votes
@@ -2096,27 +2156,27 @@

-
6
+
7
views

-
+ id="question-summary-52435489"> +
0
votes
@@ -2126,27 +2186,27 @@

-
16
+
4
views

-
+ id="question-summary-52435483"> +
0
votes
@@ -2156,30 +2216,30 @@

-
6
+
5
views

-
+ id="question-summary-52435336"> +
-
1
-
vote
+
0
+
votes
-
+ id="question-summary-52435476"> +
-
1
-
vote
+
0
+
votes
-
-
1
-
answer
+
+
0
+
answers
-
27
+
5
views
-
+ id="question-summary-52435472"> +
0
votes
@@ -2246,27 +2306,27 @@

-
11
+
2
views

-
+ id="question-summary-52435470"> +
0
votes
@@ -2276,119 +2336,119 @@

-
5
+
2
views

-
+ id="question-summary-52425112"> +
-
1
-
vote
+
0
+
votes
1
answer
-
13
+
20
views
-
+ id="question-summary-52435465"> +
-
1
-
vote
+
0
+
votes
-
-
1
-
answer
+
+
0
+
answers
-
8
+
5
views
-
+ id="question-summary-52424434"> +
1
vote
-
-
1
-
answer
+
+
0
+
answers
-
21
+
22
views
-
+ id="question-summary-52420412"> +
-
0
+
2
votes
@@ -2396,27 +2456,27 @@

-
4
+
21
views

-
+ id="question-summary-52435461"> +
0
votes
@@ -2426,27 +2486,27 @@

-
5
+
6
views

-
+ id="question-summary-52435460"> +
0
votes
@@ -2456,57 +2516,57 @@

-
5
+
4
views

-
+ id="question-summary-52435452"> +
-
1
-
vote
+
0
+
votes
0
answers
-
17
+
3
views
-
+ id="question-summary-52435451"> +
0
votes
@@ -2516,57 +2576,57 @@

answers

-
10
+
3
views
-
+ id="question-summary-52435445"> +
-
1
-
vote
+
0
+
votes
0
answers
-
14
+
5
views
-
+ id="question-summary-52435438"> +
0
votes
@@ -2576,87 +2636,87 @@

-
6
+
4
views

-
+ id="question-summary-52425210"> +
-
0
+
2
votes
-
-
0
+
+
2
answers
-
4
+
42
views
-
+ id="question-summary-44262314"> +
-
0
+
5
votes
-
-
0
+
+
6
answers
-
5
-
views
+
8k
+
views
-
+ id="question-summary-52435434"> +
0
votes
@@ -2666,57 +2726,87 @@

-
5
+
2
views

-
+ id="question-summary-52369618"> +
-
1
-
vote
+
6
+
votes
+
+
+
4
+
answers
+
+
+
169
+
views
+
+
+ +
+ +
+
+
+
0
+
votes
0
answers
-
5
+
4
views
-
+ id="question-summary-52435420"> +
0
votes
@@ -2726,27 +2816,27 @@

-
3
+
6
views

-
+ id="question-summary-52420971"> +
1
vote
@@ -2756,27 +2846,27 @@

-
21
+
19
views

-
+ id="question-summary-52435406"> +
0
votes
@@ -2786,27 +2876,27 @@

answers

-
7
+
6
views
-
+ id="question-summary-52435387"> +
0
votes
@@ -2816,27 +2906,27 @@

-
7
+
3
views

-
+ id="question-summary-52435383"> +
0
votes
@@ -2846,59 +2936,59 @@

-
6
+
4
views

-
+ id="question-summary-52435379"> +
-
1
-
vote
+
0
+
votes
0
answers
-
19
+
5
views
-
+ id="question-summary-52435376"> +
-
2
+
0
votes
@@ -2906,57 +2996,57 @@

-
16
+
5
views

-
+ id="question-summary-52435374"> +
-
1
-
vote
+
0
+
votes
-
-
1
-
answer
+
+
0
+
answers
-
9
+
3
views
-
+ id="question-summary-52435372"> +
0
votes
@@ -2966,89 +3056,89 @@

-
6
+
4
views

-
+ id="question-summary-52435366"> +
-
1
-
vote
+
0
+
votes
0
answers
-
9
+
4
views
-
+ id="question-summary-52435361"> +
-
1
-
vote
+
0
+
votes
0
answers
-
18
+
4
views
-
+ id="question-summary-52435360"> +
-
2
+
0
votes
@@ -3056,59 +3146,59 @@

answers

-
20
+
4
views
-
+ id="question-summary-52435359"> +
-
1
-
vote
+
0
+
votes
0
answers
-
7
+
3
views
-
+ id="question-summary-52435339"> +
-
2
+
0
votes
@@ -3116,117 +3206,117 @@

-
10
+
3
views

-
+ id="question-summary-52435337"> +
-
1
-
vote
+
0
+
votes
0
answers
-
9
+
3
views
-
+ id="question-summary-52434223"> +
-
1
-
vote
+
3
+
votes
0
answers
-
8
+
22
views
-
+ id="question-summary-52435230"> +
-
1
-
vote
+
2
+
votes
0
answers
-
12
+
7
views
-
+ id="question-summary-52435217"> +
1
vote
@@ -3236,27 +3326,27 @@

-
13
+
9
views

-
+ id="question-summary-52434925"> +
2
votes
@@ -3266,50 +3356,50 @@

-
20
+
8
views

-
+ id="question-summary-52434751"> +
-
1
-
vote
+
3
+
votes
0
answers
-
9
+
16
views
@@ -3321,175 +3411,171 @@

Looking for more? Browse the complete list of questions, or popular tags. Help us answer unanswered questions.

-
- + + + +
- - + + - - - + + - \ No newline at end of file + diff --git a/projects/state-mach-regex/extractlinks/urls.txt b/projects/state-mach-regex/extractlinks/urls.txt new file mode 100644 index 00000000..66ed747e --- /dev/null +++ b/projects/state-mach-regex/extractlinks/urls.txt @@ -0,0 +1,177 @@ +https://cdn.sstatic.net/Sites/stackoverflow/img/favicon +https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon +https://stackoverflow.com/ +https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon +https://ajax.googleapis.com/ajax/libs/jquery/1 +https://cdn.sstatic.net/Js/stub +https://cdn.sstatic.net/Shared/stacks +https://cdn.sstatic.net/Sites/stackoverflow/primary-unified +https://stackauth.com +https://meta.stackoverflow.com +https://cdn.sstatic.net/Img/svg-icons +https://stackoverflow.com +https://stackexchange.com/users/?tab=inbox +https://stackexchange.com/users/?tab=reputation +https://stackexchange.com +https://stackoverflow.com/users/login?ssrc=head&returnurl=https +https://stackoverflow.com/users/signup?ssrc=head&returnurl= +https://stackoverflow.com +https://stackoverflow.com +https://stackoverflow.com/help +https://chat.stackoverflow.com +https://meta.stackoverflow.com +https://stackoverflow.com/users/signup?ssrc=site_switcher& +https://stackoverflow.com/users/login?ssrc=site_switcher& +https://stackexchange.com/sites +https://stackoverflow.blog +https://meta.stackoverflow.com +https://stackoverflow.com/company/about +https://www.stackoverflowbusiness.com/?ref=topbar_help +https://stackoverflow.com/legal/cookie-policy +https://stackoverflow.com/legal/privacy-policy +https://stackoverflow.com/legal/terms-of-service/public +https://accounts.google.com/o/oauth2/auth +https://www.facebook.com/v2 +https://stackoverflow.com/legal/terms-of-service/public +https://stackoverflow.com/legal/privacy-policy +https://stackoverflow.com/legal/cookie-policy +https://www.stackoverflowbusiness.com +https://stackoverflow.com/teams +http://www.w3.org/2000/svg +https://cdn.sstatic.net/clc/clc +https://cdn.sstatic.net/clc/styles/clc +https://clc.stackoverflow.com/markup +https://www.googletagservices.com/tag/js/gpt +https://stackexchange.com/questions?tab=hot +https://physics.stackexchange.com/questions/429874/why-does-a-billiards-ball-stop-when-it-hits-another-billiards-ball-head-on +https://codegolf.stackexchange.com/questions/172455/an-ogl-edocf-challenge +https://ell.stackexchange.com/questions/180334/memorizing-without-understanding +https://academia.stackexchange.com/questions/117054/is-it-okay-to-mention-were-citing-an-article-only-because-a-reviewer-told-us-to +https://worldbuilding.stackexchange.com/questions/125510/what-is-the-earliest-point-in-history-that-big-brother-could-exist +https://workplace.stackexchange.com/questions/119547/unofficial-offer-from-company-after-failed-interview +https://math.stackexchange.com/questions/2922749/any-rectangular-shape-on-a-calculator-numpad-when-divided-by-11-gives-an-integer +https://codegolf.stackexchange.com/questions/172391/helloellolloloo-worldorldrldldd +https://german.stackexchange.com/questions/47075/what-is-a-schnorrbrief +https://worldbuilding.stackexchange.com/questions/125533/how-to-police-a-state-with-high-amount-of-gun-ownership-where-the-police-are-not +https://english.stackexchange.com/questions/464804/when-did-a-buck-start-being-used-to-mean-a-unit-of-100-e-g-a-buck-fifty-f +https://electronics.stackexchange.com/questions/397062/why-cant-i-successfully-send-messages-over-rs232 +https://security.stackexchange.com/questions/194166/why-is-suid-disabled-for-shell-scripts-but-not-for-binaries +https://codegolf.stackexchange.com/questions/172480/build-a-markdown-bomb +https://history.stackexchange.com/questions/48216/what-is-the-origin-of-3-meals-a-day +https://cooking.stackexchange.com/questions/92362/how-can-i-get-rid-of-as-much-oil-from-my-schnitzel-after-deep-frying-it +https://money.stackexchange.com/questions/100157/why-auto-renew-instead-of-canceling-the-subscription-after-free-trial +https://scifi.stackexchange.com/questions/195206/is-the-2016-dirk-gentlys-holistic-detective-agency-tv-series-a-direct-adaptat +https://superuser.com/questions/1359065/does-leaving-your-laptop-powered-on-unsuspended-and-moving-it-around-risk-damagi +https://electronics.stackexchange.com/questions/396653/why-is-the-time-constant-63-2-and-not-50-or-70 +https://tex.stackexchange.com/questions/451730/using-biblatex-for-dd +https://interpersonal.stackexchange.com/questions/18607/how-to-say-no-to-an-extremely-pushy-friend +https://security.stackexchange.com/questions/194048/can-someone-without-the-wifi-login-and-no-physical-access-to-a-router-still-acce +https://money.stackexchange.com/questions/100119/isnt-i-bought-blank-as-a-tax-writeoff-complete-nonsense +https://stackoverflow.com +https://stackoverflow.com +https://stackoverflow.com/jobs +https://stackoverflow.com/jobs/directory/developer-jobs +https://stackoverflow.com/jobs/salary +https://www.stackoverflowbusiness.com +https://stackoverflow.com/teams +https://www.stackoverflowbusiness.com/talent +https://www.stackoverflowbusiness.com/advertise +https://stackoverflow.com/enterprise +https://stackoverflow.com/company/about +https://stackoverflow.com/company/about +https://stackoverflow.com/company/press +https://stackoverflow.com/company/work-here +https://stackoverflow.com/legal +https://stackoverflow.com/legal/privacy-policy +https://stackoverflow.com/company/contact +https://stackexchange.com +https://stackoverflow.com +https://serverfault.com +https://superuser.com +https://webapps.stackexchange.com +https://askubuntu.com +https://webmasters.stackexchange.com +https://gamedev.stackexchange.com +https://tex.stackexchange.com +https://softwareengineering.stackexchange.com +https://unix.stackexchange.com +https://apple.stackexchange.com +https://wordpress.stackexchange.com +https://gis.stackexchange.com +https://electronics.stackexchange.com +https://android.stackexchange.com +https://security.stackexchange.com +https://dba.stackexchange.com +https://drupal.stackexchange.com +https://sharepoint.stackexchange.com +https://ux.stackexchange.com +https://mathematica.stackexchange.com +https://salesforce.stackexchange.com +https://expressionengine.stackexchange.com +https://pt.stackoverflow.com +https://blender.stackexchange.com +https://networkengineering.stackexchange.com +https://crypto.stackexchange.com +https://codereview.stackexchange.com +https://magento.stackexchange.com +https://softwarerecs.stackexchange.com +https://dsp.stackexchange.com +https://emacs.stackexchange.com +https://raspberrypi.stackexchange.com +https://ru.stackoverflow.com +https://codegolf.stackexchange.com +https://es.stackoverflow.com +https://ethereum.stackexchange.com +https://datascience.stackexchange.com +https://arduino.stackexchange.com +https://bitcoin.stackexchange.com +https://stackexchange.com/sites +https://photo.stackexchange.com +https://scifi.stackexchange.com +https://graphicdesign.stackexchange.com +https://movies.stackexchange.com +https://music.stackexchange.com +https://worldbuilding.stackexchange.com +https://cooking.stackexchange.com +https://diy.stackexchange.com +https://money.stackexchange.com +https://academia.stackexchange.com +https://law.stackexchange.com +https://stackexchange.com/sites +https://english.stackexchange.com +https://skeptics.stackexchange.com +https://judaism.stackexchange.com +https://travel.stackexchange.com +https://christianity.stackexchange.com +https://ell.stackexchange.com +https://japanese.stackexchange.com +https://gaming.stackexchange.com +https://bicycles.stackexchange.com +https://rpg.stackexchange.com +https://anime.stackexchange.com +https://puzzling.stackexchange.com +https://mechanics.stackexchange.com +https://stackexchange.com/sites +https://mathoverflow.net +https://math.stackexchange.com +https://stats.stackexchange.com +https://cstheory.stackexchange.com +https://physics.stackexchange.com +https://chemistry.stackexchange.com +https://biology.stackexchange.com +https://cs.stackexchange.com +https://philosophy.stackexchange.com +https://stackexchange.com/sites +https://meta.stackexchange.com +https://stackapps.com +https://api.stackexchange.com +https://data.stackexchange.com +https://area51.stackexchange.com +https://stackoverflow.blog?blb=1 +https://www.facebook.com/officialstackoverflow/ +https://twitter.com/stackoverflow +https://linkedin.com/company/stack-overflow +https://creativecommons.org/licenses/by-sa/3 +https://stackoverflow.blog/2009/06/25/attribution-required/ +https://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc +https://www.google-analytics.com/analytics From eec40a02e72fbe74d34195d26d3f919eadb08002 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 21:37:23 -0500 Subject: [PATCH 7/9] configure readline to print back area, prefix and suffix on basic regex phone match --- projects/state-mach-regex/phone/phone.js | 28 ++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/projects/state-mach-regex/phone/phone.js b/projects/state-mach-regex/phone/phone.js index bf317169..39d8b328 100644 --- a/projects/state-mach-regex/phone/phone.js +++ b/projects/state-mach-regex/phone/phone.js @@ -1,23 +1,19 @@ -var readline = require('readline'); +let readline = require('readline') -var rl = readline.createInterface({ +let rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false -}); +}) - -// This code reads a line at a time from stdin +let regex = /^(\d{3})(\d{3})(\d{4})$/ rl.on('line', function (line) { - - // !!!! IMPLEMENT ME - - // Come up with the phone regex - - // Find matches - - // If match found, print number with no spaces, parens, or dashes - - // Else print that no number was found -}); + console.log(regex.test(line)) + console.log('match:', matches) + + matches = regex.exec(line).slice(1,4) + console.log('Area code:', matches[0]) + console.log('Prefix:', matches[1]) + console.log('Suffix:', matches[2]) +}) From dc93a4b77389dddf809be9c4c1e31be1a70f3b82 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 21:47:18 -0500 Subject: [PATCH 8/9] regex is mostly working now; circle back to check for edge cases --- projects/state-mach-regex/phone/phone.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/projects/state-mach-regex/phone/phone.js b/projects/state-mach-regex/phone/phone.js index 39d8b328..906da093 100644 --- a/projects/state-mach-regex/phone/phone.js +++ b/projects/state-mach-regex/phone/phone.js @@ -6,14 +6,19 @@ let rl = readline.createInterface({ terminal: false }) -let regex = /^(\d{3})(\d{3})(\d{4})$/ +let regex = /^(\(\d{3}\)|\d{3})[\s-]*(\d{3})[\s-]*(\d{4})$/ +console.log('Enter a phone number:') rl.on('line', function (line) { - console.log(regex.test(line)) - console.log('match:', matches) - - matches = regex.exec(line).slice(1,4) - console.log('Area code:', matches[0]) - console.log('Prefix:', matches[1]) - console.log('Suffix:', matches[2]) + if(regex.test(line)) { + let matches = regex.exec(line).slice(1,4) + console.log('match:', matches) + console.log('Area code:', matches[0]) + console.log('Prefix:', matches[1]) + console.log('Suffix:', matches[2]) + } + else { + console.log('Invalid phone number. Try again.') + } }) + From f57e6912cc391a3c2296900b6d2fb678161486e5 Mon Sep 17 00:00:00 2001 From: Andrew Jarrett Date: Thu, 20 Sep 2018 21:59:02 -0500 Subject: [PATCH 9/9] complete theory of computation sprint --- projects/state-mach-regex/phone/phone.js | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/projects/state-mach-regex/phone/phone.js b/projects/state-mach-regex/phone/phone.js index 906da093..1d0774e7 100644 --- a/projects/state-mach-regex/phone/phone.js +++ b/projects/state-mach-regex/phone/phone.js @@ -6,19 +6,20 @@ let rl = readline.createInterface({ terminal: false }) -let regex = /^(\(\d{3}\)|\d{3})[\s-]*(\d{3})[\s-]*(\d{4})$/ +let regex = /^(\(\d{3}\)\s?|\d{3})[\s-]?(\d{3})[\s-]?(\d{4})$/ -console.log('Enter a phone number:') +console.log(`\n Enter a phone number:`) rl.on('line', function (line) { - if(regex.test(line)) { - let matches = regex.exec(line).slice(1,4) - console.log('match:', matches) - console.log('Area code:', matches[0]) - console.log('Prefix:', matches[1]) - console.log('Suffix:', matches[2]) - } - else { - console.log('Invalid phone number. Try again.') - } + if(!regex.test(line)) + return console.log('Invalid phone number. Try again.') + + let matches = regex.exec(line).slice(1,4) + + console.log(` +Area code :: ${matches[0]} + Prefix :: ${matches[1]} + Suffix :: ${matches[2]} + +Enter another phone number:`) })