回答編集履歴

3

Update

2022/05/19 04:28

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,5 +1,5 @@
1
- negative lookahead(`?!`) + make subpattern(`?:`)
1
+ negative lookahead(`?!`) を利用する場合。
2
2
  ```php
3
3
  //if(preg_match("/^\s*([\"'|'])[^\1]*?\g{1}\s*$/", $test)){
4
- if(preg_match("/^\s*([\"'])(?:(?!\\1).)*\\1\s*$/", $test)){
4
+ if(preg_match("/^\s*([\"'])((?!\\1).)*\\1\s*$/", $test)){
5
5
  ```

2

Update

2022/05/19 03:46

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,5 +1,5 @@
1
1
  negative lookahead(`?!`) + make subpattern(`?:`)
2
2
  ```php
3
3
  //if(preg_match("/^\s*([\"'|'])[^\1]*?\g{1}\s*$/", $test)){
4
- if(preg_match("/^\s*([\"'])(?:(?!\\1).)+\\1\s*$/", $test)){
4
+ if(preg_match("/^\s*([\"'])(?:(?!\\1).)*\\1\s*$/", $test)){
5
5
  ```

1

Update

2022/05/19 03:42

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,3 +1,4 @@
1
+ negative lookahead(`?!`) + make subpattern(`?:`)
1
2
  ```php
2
3
  //if(preg_match("/^\s*([\"'|'])[^\1]*?\g{1}\s*$/", $test)){
3
4
  if(preg_match("/^\s*([\"'])(?:(?!\\1).)+\\1\s*$/", $test)){