Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何编写表示if';字符串以BT';开头;?_Javascript_Regex - Fatal编程技术网

Javascript 如何编写表示if';字符串以BT';开头;?

Javascript 如何编写表示if';字符串以BT';开头;?,javascript,regex,Javascript,Regex,如果单词/字符串以字母“BT”开头,如何编写正则表达式 以下是我使用的代码: if(val.match(/^\S{5,}$/)){ if(val.match(/^BT/)){ alert('Unfortunately you cannot buy or sell registrations in the Auctions if you live in Northern Ireland'); return false;

如果单词/字符串以字母“BT”开头,如何编写正则表达式

以下是我使用的代码:

    if(val.match(/^\S{5,}$/)){

        if(val.match(/^BT/)){

            alert('Unfortunately you cannot buy or sell registrations in the Auctions if you live in Northern Ireland');
            return false;

        }else{

            postcode.val(val.slice(0, -3)+' '+val.slice(-3));
            $('#Postcodelookup').fadeIn(300);

        }
    }else{...

由于我对使用regex还不熟悉,因此非常感谢您的帮助,谢谢您的
/\bBT/
您的
/\bBT/

/^BT/
如果字符串以
BT
开头,则匹配。只匹配
BT
;如果希望匹配结果包含整个单词,请使用
/^BT\w*/
;如果希望它返回整个字符串,请使用
/^BT[\s\s]*/

/\bBT/
如果单词以
BT
开头,则匹配。只匹配
BT
;如果希望匹配结果包含整个单词,请使用
/\bBT\w*/

/\bBT/
如果字符串以
BT
开头,则匹配。只匹配
BT
;如果希望匹配结果包含整个单词,请使用
/^BT\w*/
;如果希望它返回整个字符串,请使用
/^BT[\s\s]*/

/\bBT/

如果单词以
BT
开头,则匹配。只匹配
BT
;如果您希望匹配结果包含整个单词,请使用
/\bBT\w*/

@Gumbo&Ignacio-是否有一种方法可以使用JavaScript对其进行自定义,使其仅在单词开始时提取BT?Thanks@Ignacio-我已经添加了我正在使用的代码,但它不起作用???似乎很简单,我遗漏了什么???@Ignacio-以下是我对
val
var postcode=$(this),val=postcode.val()的内容@Nasir:嗯,这很好,但是。。。它是什么?@Nasir:既然
B
是一个单词字符,而且
\B
只有在前面没有其他单词字符时才匹配,那么您可以使用
\WBT
BT
@Gumbo&Ignacio之前获取非单词字符-有没有办法使用JavaScript对其进行定制,使其仅在单词开始时提取BT?Thanks@Ignacio-我已经添加了我正在使用的代码,但它不起作用???似乎很简单,我遗漏了什么???@Ignacio-以下是我对
val
var postcode=$(this),val=postcode.val()的内容@Nasir:嗯,这很好,但是。。。它是什么?@Nasir:因为
B
是一个单词字符,并且
\B
只有在前面没有其他单词字符时才匹配,所以您可以使用
\WBT
来获取
BT
前面的非单词字符。
/\bBT/