javascript - How to use regular expressions in js to find the string between two specific characters in a string?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-07 09:23:17
0
2
633

For example, I now have a string "@3131 @aba21bas @zxcc@213wd cccaf21212"
I now want to extract all the characters between @ and spaces in this string
The above string has been extracted The final result should be 3131, aba21bas, zxcc@213wd
How should this regular expression be written? ? (js writing method)

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
某草草

The match method in js cannot get the grouping results in the regular/g mode. For example, the @ and spaces cannot be removed from such results:

"@3131 @aba21bas @zxcc@213wd cccaf21212".match(/@([^\s]*?)\s/g)
//  ["@3131 ", "@aba21bas ", "@zxcc@213wd "]

So you can change it to the reg.exec method, for example:

function pick(str){
    var reg = /@([^\s]*?)\s/g, ret = [];
    while(arr = reg.exec(str)) ret.push(arr[1]);
    return ret;
}
pick("@3131 @aba21bas @zxcc@213wd cccaf21212" )
给我你的怀抱

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template