回答編集履歴

2

code 修正

2021/03/29 23:36

投稿

seastar3
seastar3

スコア2287

test CHANGED
@@ -6,21 +6,29 @@
6
6
 
7
7
 
8
8
 
9
- str1 = aryStr[0];
9
+ $str1 = $aryStr[0];
10
10
 
11
- str_num1 = aryStr[1];
11
+ $str_num1 = $aryStr[1];
12
12
 
13
- str_num2 = aryStr[2];
13
+ $str_num2 = $aryStr[2];
14
+
15
+ preg_match('/\d+$/', $aryStr[3], $str_tmp);
16
+
17
+ $str_num3 = $str_tmp[0];
18
+
19
+ $str2 = substr($aryStr[3],0, strlen($aryStr[3]) - strlen($str_num3));
14
20
 
15
21
 
16
22
 
17
- str2 = Regex.Replace (aryStr[3], @"[0-9]", "");
23
+ // 以下2行のコードは文字列に数字が含まれると間違えた文字列を返す。
18
24
 
25
+ // $str2 = preg_replace ("/[0-9]/", "", $aryStr[3]);
26
+
19
- str_num3 = Regex.Replace (aryStr[3], @"[^0-9]", "");
27
+ // $str_num3 = preg_replace ("/^[0-9]/", "", $aryStr[3]);
20
28
 
21
29
 
22
30
 
23
- echo str1." ".str_num1." ".str_num2." ".str2." ".str_num3."<br>";
31
+ echo str1." ".str_num1." ".str_num2." ".str2." ".str_num3."\n";
24
32
 
25
33
  ```
26
34
 

1

code 修正

2021/03/29 23:36

投稿

seastar3
seastar3

スコア2287

test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
 
22
22
 
23
- echo str1." ".str_num1." ".str_num2." ".str2." ".str_num2."<br>";
23
+ echo str1." ".str_num1." ".str_num2." ".str2." ".str_num3."<br>";
24
24
 
25
25
  ```
26
26