teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

インデントの修正

2019/03/25 14:50

投稿

starororo
starororo

スコア14

title CHANGED
File without changes
body CHANGED
@@ -29,14 +29,14 @@
29
29
  ```php
30
30
  $file = file_get_contents("test.txt");
31
31
 
32
- $deleteCommentPattern1 = "#//[\s\S]*\n#";
32
+ $deleteCommentPattern1 = "#//[\s\S]*\n#";
33
- $deleteCommentPattern2 = "#/*[\s\S]**/#";
33
+ $deleteCommentPattern2 = "#/*[\s\S]**/#";
34
34
 
35
- $deleteCommentSource = preg_replace($deleteCommentPattern1, "", $file);
35
+ $deleteCommentSource = preg_replace($deleteCommentPattern1, "", $file);
36
- $deleteCommentSource = preg_replace($deleteCommentPattern2, "", $file);
36
+ $deleteCommentSource = preg_replace($deleteCommentPattern2, "", $file);
37
37
 
38
- $writeFile = fopen("writetest.txt", "w");
38
+ $writeFile = fopen("writetest.txt", "w");
39
- $writeFileReturn = fwrite($writeFile, $deleteCommentSource);
39
+ $writeFileReturn = fwrite($writeFile, $deleteCommentSource);
40
40
  ```
41
41
 
42
42
  出力後のwrite.txt

3

誤りの修正

2019/03/25 14:50

投稿

starororo
starororo

スコア14

title CHANGED
File without changes
body CHANGED
@@ -32,8 +32,8 @@
32
32
  $deleteCommentPattern1 = "#//[\s\S]*\n#";
33
33
  $deleteCommentPattern2 = "#/*[\s\S]**/#";
34
34
 
35
- $deleteCommentSource = preg_replace($deleteCommentPattern1, "", $jackFile);
35
+ $deleteCommentSource = preg_replace($deleteCommentPattern1, "", $file);
36
- $deleteCommentSource = preg_replace($deleteCommentPattern2, "", $jackFile);
36
+ $deleteCommentSource = preg_replace($deleteCommentPattern2, "", $file);
37
37
 
38
38
  $writeFile = fopen("writetest.txt", "w");
39
39
  $writeFileReturn = fwrite($writeFile, $deleteCommentSource);

2

ソースコードの修正

2019/03/25 14:43

投稿

starororo
starororo

スコア14

title CHANGED
File without changes
body CHANGED
@@ -43,5 +43,6 @@
43
43
  ```txt
44
44
  // Lorem ipsum dolor sit amet
45
45
 
46
+
46
47
  tempor incididunt ut labore et dolore magna aliqua
47
48
  ```

1

プログラムの対象ファイルソースコードの追記

2019/03/25 13:57

投稿

starororo
starororo

スコア14

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  // コメントコメントコメント
5
5
 
6
- ↑のようなテキトファイルに存在するコメントを削除するために、それに一致する正規表現パターンの作成を試みているのですがうまくいきません。
6
+ ↑のような、プログラムのソーコード中に存在するコメントを削除するために、それに一致する正規表現パターンの作成を試みているのですがうまくいきません。
7
7
 
8
8
  試したものは以下の通りです(#はデリミタです。念のため)。
9
9
 
@@ -12,5 +12,36 @@
12
12
  "#//.*#"
13
13
  "#//.*\n#"
14
14
 
15
+
16
+ 以下はソースコードです(便宜上、多少書き換えています)
17
+ 書き換えに伴いタイポ等の誤りが存在する可能性があります。
18
+
19
+ test.txt
20
+ ```txt
21
+ // Lorem ipsum dolor sit amet
22
+ /** consectetur adipiscing elit, sed do eiusmod */
23
+
15
- 同様の方法で他のタイプのコメント削除はできているため、関数名や変名などのタイポによるミスはないと思われます。
24
+ tempor incididunt ut labore et dolore magna aliqua
25
+
26
+ ```
27
+
16
- ご教授のほど宜しくお願いします。
28
+ deleteComment.php
29
+ ```php
30
+ $file = file_get_contents("test.txt");
31
+
32
+ $deleteCommentPattern1 = "#//[\s\S]*\n#";
33
+ $deleteCommentPattern2 = "#/*[\s\S]**/#";
34
+
35
+ $deleteCommentSource = preg_replace($deleteCommentPattern1, "", $jackFile);
36
+ $deleteCommentSource = preg_replace($deleteCommentPattern2, "", $jackFile);
37
+
38
+ $writeFile = fopen("writetest.txt", "w");
39
+ $writeFileReturn = fwrite($writeFile, $deleteCommentSource);
40
+ ```
41
+
42
+ 出力後のwrite.txt
43
+ ```txt
44
+ // Lorem ipsum dolor sit amet
45
+
46
+ tempor incididunt ut labore et dolore magna aliqua
47
+ ```