-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregexpPosta.js
More file actions
40 lines (35 loc) · 881 Bytes
/
Copy pathregexpPosta.js
File metadata and controls
40 lines (35 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const main = (
L='111*1=',
A='1*=',
before=[
/111\*([1]+)=/,
],
after=[
'xxx'
]) => {
let contains = L.match(new RegExp(`^[${A}]+$`, 'g'))
if (!contains) {
console.error('Строка не состоит из Алфавита')
return L
}
let c = before.find(b => L.search(b) !==-1)
while (c) {
let j = before.indexOf(c)
console.log(`Номер правила ${j} => Lenta ${L}`)
let m = L.match(c)[1]
let r = L.replace(c, after[j])
L = r.replace(/x/g, m)
c = before.find(b => L.search(b) !==-1)
}
return L
}
// Read from files
const fs = require('fs')
console.log(
main(
fs.readFileSync('input/lenta', 'utf8'),
fs.readFileSync('input/alphabet', 'utf8'),
JSON.parse(fs.readFileSync('input/before.json', 'utf8')).map(v => new RegExp(v)),
JSON.parse(fs.readFileSync('input/after.json'))
)
)