/**
* 取出中括号内的内容
* @param text
* @returns {string}
*/
export function getBracketStr(text) {
let result = ''
if (isObjEmpty(text))
return result
let regex = /\[(.+?)\]/g;
let options = text.match(regex)
if (!isObjEmpty(options)) {
let option = options[0]
if (!isObjEmpty(option)) {
result = option.substring(1, option.length - 1)
}
}
return result
}
/**
* 取出小括号内的内容
* @param text
* @returns {string}
*/
export function getParenthesesStr(text) {
let result = ''
if (isObjEmpty(text))
return result
let regex = /\((.+?)\)/g;
let options = text.match(regex)
if (!isObjEmpty(options)) {
let option = options[0]
if (!isObjEmpty(option)) {
result = option.substring(1, option.length - 1)
}
}
return result
}
JavaScript取出字符串中括号里的内容
最新推荐文章于 2026-04-12 21:46:59 发布
本文介绍了一种从文本中提取中括号及小括号内内容的方法,使用正则表达式匹配并返回所需字符串。适用于需要解析带括号文本的场景。

510

被折叠的 条评论
为什么被折叠?



