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

回答編集履歴

2

最後のデータ

2019/05/30 10:16

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -6,8 +6,8 @@
6
6
  # sample
7
7
  ```PHP
8
8
  $str = "[2019-05-30_17:57:12.234] [testPG] [info] [test,hogehohe,20190530175712234]";
9
- $pattern="/(?<=[).*?(?=])/mis";
9
+ $pattern="/(?!.*?[.*?])(?<=[).*?(?=])/";
10
- if(preg_match_all($pattern,$str,$match)){
10
+ if(preg_match($pattern,$str,$match)){
11
- print $match[0][count($match[0])-1];
11
+ print $match[0];
12
12
  }
13
13
  ```

1

ちょうせい

2019/05/30 10:16

投稿

yambejp
yambejp

スコア117946

answer CHANGED
@@ -1,4 +1,13 @@
1
1
  - 前から4番目のデータを取り出したいのか
2
2
  - 最後のデータを取り出したいのか
3
3
 
4
- によってやり方が変わります
4
+ によってやり方が変わります
5
+
6
+ # sample
7
+ ```PHP
8
+ $str = "[2019-05-30_17:57:12.234] [testPG] [info] [test,hogehohe,20190530175712234]";
9
+ $pattern="/(?<=[).*?(?=])/mis";
10
+ if(preg_match_all($pattern,$str,$match)){
11
+ print $match[0][count($match[0])-1];
12
+ }
13
+ ```