JavaScript取出字符串中括号里的内容
作者:
RaoMeng | 来源:发表于
2018-11-02 10:21 被阅读0次
/**
* 取出中括号内的内容
* @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取出字符串中括号里的内容
本文链接:https://www.haomeiwen.com/subject/wpeqxqtx.html
网友评论