我有这些话
verification-asdflkaasidmf
verification-sadfim-aisdmfim
我想匹配第一个verification-asdflkaasidmf
但不匹配第二个(有两个破折号)
答案 0 :(得分:2)
另一种方法是:
import { AngularFireAuth } from 'angularfire2/auth';
model : any = {} ;
private afAuth : AngularFireAuth,
regWithEP () {
this.afAuth.auth.createUserWithEmailAndPassword(this.model.email, this.model.password).then((user) => {
/* IMPORTANT !! */
/* EXPLICIT CHECK IF USER IS RETURNED FROM FIREBASE SERVICE !! */
if (user) {
console.log(user);
/* Here user is available and is the same as auth.currentUser */
this.afAuth.auth.currentUser.getToken().then((token) => {
//token is available here
//set token to currentUser, signIn , re-direct etc.
});
}
});
}
其中包括以下内容:
^[^-]*\-[^-]*$
答案 1 :(得分:2)
您可以使用此正则表达式:
/^\w+-\w+$/
此正则表达式匹配开头的单词,后跟连字符,后跟另一个单词。
let arr = ['verification-asdflkaasidmf',
'verification-sadfim-aisdmfim'
];
let regex = /^\w+-\w+$/;
for (i=0; i<arr.length; i++) {
console.log(arr[i], regex.test(arr[i]));
}