質問編集履歴
4
インデントの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,21 +60,21 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
|
63
|
+
$deleteCommentPattern1 = "#//[\s\S]*\n#";
|
64
64
|
|
65
|
-
|
65
|
+
$deleteCommentPattern2 = "#/*[\s\S]**/#";
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
|
69
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern1, "", $file);
|
70
70
|
|
71
|
-
|
71
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern2, "", $file);
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
|
75
|
+
$writeFile = fopen("writetest.txt", "w");
|
76
76
|
|
77
|
-
|
77
|
+
$writeFileReturn = fwrite($writeFile, $deleteCommentSource);
|
78
78
|
|
79
79
|
```
|
80
80
|
|
3
誤りの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,9 +66,9 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
$deleteCommentSource = preg_replace($deleteCommentPattern1, "", $
|
69
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern1, "", $file);
|
70
70
|
|
71
|
-
$deleteCommentSource = preg_replace($deleteCommentPattern2, "", $
|
71
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern2, "", $file);
|
72
72
|
|
73
73
|
|
74
74
|
|
2
ソースコードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,6 +88,8 @@
|
|
88
88
|
|
89
89
|
|
90
90
|
|
91
|
+
|
92
|
+
|
91
93
|
tempor incididunt ut labore et dolore magna aliqua
|
92
94
|
|
93
95
|
```
|
1
プログラムの対象ファイルソースコードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
↑のような
|
11
|
+
↑のような、プログラムのソースコード中に存在するコメントを削除するために、それに一致する正規表現パターンの作成を試みているのですがうまくいきません。
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -26,6 +26,68 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
同様の方法で他のタイプのコメント削除はできているため、関数名や変名などのタイポによるミスはないと思われます。
|
30
29
|
|
30
|
+
|
31
|
+
以下はソースコードです(便宜上、多少書き換えています)
|
32
|
+
|
33
|
+
書き換えに伴いタイポ等の誤りが存在する可能性があります。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
test.txt
|
38
|
+
|
39
|
+
```txt
|
40
|
+
|
41
|
+
// Lorem ipsum dolor sit amet
|
42
|
+
|
43
|
+
/** consectetur adipiscing elit, sed do eiusmod */
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
tempor incididunt ut labore et dolore magna aliqua
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
31
|
-
|
55
|
+
deleteComment.php
|
56
|
+
|
57
|
+
```php
|
58
|
+
|
59
|
+
$file = file_get_contents("test.txt");
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
$deleteCommentPattern1 = "#//[\s\S]*\n#";
|
64
|
+
|
65
|
+
$deleteCommentPattern2 = "#/*[\s\S]**/#";
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern1, "", $jackFile);
|
70
|
+
|
71
|
+
$deleteCommentSource = preg_replace($deleteCommentPattern2, "", $jackFile);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
$writeFile = fopen("writetest.txt", "w");
|
76
|
+
|
77
|
+
$writeFileReturn = fwrite($writeFile, $deleteCommentSource);
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
出力後のwrite.txt
|
84
|
+
|
85
|
+
```txt
|
86
|
+
|
87
|
+
// Lorem ipsum dolor sit amet
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
tempor incididunt ut labore et dolore magna aliqua
|
92
|
+
|
93
|
+
```
|