[正则]这段字符串如何分别提取前后文字

[中国]你好中国

用正则分别提取中国,你好中国


import re

str_1 = '[中国]你好中国'
str_2 = re.findall('\[(.*)\]',str_1)[0]
str_3 = re.findall('\[.*\](.*)',str_1)[0]
print(str_2,str_3)
    const exp = /\[(.*)\](.*)/;
    const result = '[中国]你好中国'.match(exp)
    console.log(result[1], result[2])//中国 你好中国

当然上面这种默认分组不够正规,也可以自行命名:

    const exp = /\[(?<before>.*)\](?<after>.*)/;
    const result = '[中国]你好中国'.match(exp)
    const { groups } = result
    console.log(groups.before, groups.after)//中国 你好中国