Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

((2+3)+(3*4))+2---->['(2 + 3)+(3 * 4)', '2 + 3', '3 * 4'] #57

Open
Sunny-117 opened this issue Nov 3, 2022 · 0 comments
Open

((2+3)+(3*4))+2---->['(2 + 3)+(3 * 4)', '2 + 3', '3 * 4'] #57

Sunny-117 opened this issue Nov 3, 2022 · 0 comments

Comments

@Sunny-117
Copy link
Owner

/**
 * fzq 4.23
 */
let str = '((2+3)+(3*4))+2'
function print(str) {
    const res = []
    matchRes = ''
    str = str.replace(/\(\(([\d\D]+)\)\)/g, function (match) {
        matchRes = match.substring(1, match.length - 1)
        res.push(matchRes)
    })
    matchRes.replace(/\([\s\S]+?\)/g, function (match) {
        // 非贪婪匹配
        res.push(match)
    })
    return res
}
console.log(print(str));// ['(2 + 3)+(3 * 4)',   '2 + 3',  '3 * 4']
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant