来自referrer的Regexp JS

时间:2012-11-08 10:34:44

标签: javascript

我需要检查推荐人是否有单词“profile”我需要将profile /(.*?)放在var中。我怎么能在js中做到这一点?

<script type="text/javascript">
var ref = document.referrer;
if( ~ref.indexOf("profile") ) {
  alert('coincidence found!');
}

 </script>

2 个答案:

答案 0 :(得分:0)

<script>
var str="Is this all there is?";
var patt1=/[^a-h]/g;
document.write(str.match(patt1));
</script>

结果:I,s,t,i,s ,, l,l,t,r ,, i,s,?

检查link The [^abc] expression is used to find any character not between the brackets.

这太过link

答案 1 :(得分:0)

var ref = document.referrer;
ref.match(/(?:profile).+/,(match)=> {
    console.log(match)
})
相关问题