正则表达式获取url后面的参数

getUrl(){

      	const URL = window.location.href

      	const regex = /user_id=([0-9]{1,20})/;//0-9代表0-9的任意数字,1-20表示1-20位数字

      	const str = URL

      	let m;

      	if ( (m = regex.exec(str)) !== null) {

        	 console.log(m[1])//m[1]就是截取出来的参数,这是指定

      	}

   }

猜你喜欢

转载自blog.csdn.net/qq_32113629/article/details/81079515