ไปๅคฉ้่ฆ็จๆญฃ่ฆๅผๆพๅบ็ฌฆๅ xxx[yyy] ๅพ้ข้ ไปปๆๅ งๅฎน็็ตๆ,็ด้ไธไธไธ็จฎ่ช่จๆ้บผๆไฝๆญฃ่ฆๅผ。
PHP
<?php
$pattern = '/\w+\[\w+\].*/i';
$strings = [
'aaa[bbb]',
'1234[bbb][cccc]',
'[111][22]',
'dd[gg]ff',
'aa[',
'aaa][bbbb',
'aaabbbccc',
];
foreach ($strings as $s) {
var_dump($s.' is '.preg_match($pattern, $s));
}
Python
import re
pattern = r'\w+\[\w+\].*';
strings = [
'aaa[bbb]',
'1234[bbb][cccc]',
'[111][22]',
'dd[gg]ff',
'aa[',
'aaa][bbbb',
'aaabbbccc'
];
for s in strings:
print('%s is %s' % (s, True if re.match(pattern, s, re.IGNORECASE) else False))
Node.js
const pattern = /\w+\[\w+\].*/i;
const strings = [
'aaa[bbb]',
'1234[bbb][cccc]',
'[111][22]',
'dd[gg]ff',
'aa[',
'aaa][bbbb',
'aaabbbccc'
];
for (v of strings) {
console.log(v, 'is', pattern.test(v));
}