回答編集履歴
1
内容修正
test
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
一旦バラして、くつける、かな。
|
2
|
+
|
3
|
+
> 大変申し訳ございません。文字列は空白が無い状態からの置換をお伺いするべきでしたが、...
|
2
4
|
|
3
5
|
|
4
6
|
|
5
7
|
```js
|
6
8
|
|
7
|
-
var text = "aaaa <aa>
|
9
|
+
var text = "aaaa <aa>(aaa)aaaaa";
|
8
10
|
|
9
11
|
|
10
12
|
|
11
13
|
var result =
|
12
14
|
|
15
|
+
text
|
16
|
+
|
17
|
+
.replace(new RegExp("([<( ])", "g"), "\n$1")
|
18
|
+
|
19
|
+
.replace(new RegExp("([>) ])", "g"), "$1\n")
|
20
|
+
|
13
|
-
|
21
|
+
.split("\n")
|
14
22
|
|
15
23
|
.map(it => {
|
16
24
|
|
@@ -20,7 +28,7 @@
|
|
20
28
|
|
21
29
|
})
|
22
30
|
|
23
|
-
.join("
|
31
|
+
.join("")
|
24
32
|
|
25
33
|
|
26
34
|
|
@@ -30,8 +38,40 @@
|
|
30
38
|
|
31
39
|
|
32
40
|
|
33
|
-
// aaaa <aa>
|
41
|
+
// aaaa <aa>(aaa)aaaaa
|
34
42
|
|
35
|
-
// BBBB <aa>
|
43
|
+
// BBBB <aa>(aaa)BBBBB
|
36
44
|
|
37
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
~~ var text = "aaaa <aa> (aaa) aaaaa"; ~~
|
50
|
+
|
51
|
+
~~ ~~
|
52
|
+
|
53
|
+
~~ var result = ~~
|
54
|
+
|
55
|
+
~~ text.split(" ") ~~
|
56
|
+
|
57
|
+
~~ .map(it => { ~~
|
58
|
+
|
59
|
+
~~ if (it.match(/^[<(][^<(]+[>)]$/)) return it; ~~
|
60
|
+
|
61
|
+
~~ else return it.replace(new RegExp("a", "g"), "B"); ~~
|
62
|
+
|
63
|
+
~~ }) ~~
|
64
|
+
|
65
|
+
~~ .join(" ") ~~
|
66
|
+
|
67
|
+
~~ ~~
|
68
|
+
|
69
|
+
~~ console.log(text); ~~
|
70
|
+
|
71
|
+
~~ console.log(result); ~~
|
72
|
+
|
73
|
+
~~ ~~
|
74
|
+
|
75
|
+
~~ // aaaa <aa> (aaa) aaaaa ~~
|
76
|
+
|
77
|
+
~~ // BBBB <aa> (aaa) BBBBB ~~
|