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)
某草草2017-06-07 09:25:17
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" )