简体   繁体   English

在一行中用 JavaScript 中的正则表达式解析 email; 使右不区分大小写但保持左

[英]Parse email by RegExp in JavaScript in one line; make right case insensitive but keep left

  1. From my code:从我的代码:

     //yagh... apparently there's an off-chance email is case sensitive... console.log('yooooooooo0 ' + name.substr(name.indexOf('@')+1)); //console.log('yooooooooo1 ' + name.substr(name.indexOf('@')+1).toLowercase()); console.log('yooooooooo1 ' + name.substr(name.indexOf('@')+1).toLowerCase()); console.log('yooooooooo2 ' + name.substr(name.indexOf('@'),0)); console.log('yooooooooo3 ' + name.split('@')[0]); console.log('yooooooooo4 ' + /[^@]*/.exec(name)[0]);//hmmm mh console.log('yooooooooo4_2 ' + /[^@]*$/.exec(name)[0]);//hmmm mh //hm yea okay ya console.log(name);//nondestructive and //pff... console.log((/[^@]*/.exec(name)[0])+'@'+(/[^@]*$/.exec(name)[0]).toLowerCase); let tmp = (/[^@]*/.exec(name)[0])+'@'+ (/[^@]*$/.exec(name)[0]).toLowerCase; console.log(tmp); console.log((/[^@]*/.exec(name)[0])+'@'+name.substr(name.indexOf('@')+1).toLowerCase()); var pass = $('#pass1').val(); var crypto = window.crypto || window.msCrypto; if(crypto.subtle) {
  2. Say the email that comes with is a@b.C .说自带的 email 是a@b.C The point is, I just found that email is only case insensitive right of the @ .关键是,我刚刚发现 email 只是@不区分大小写的权利。 In theory, admins can choose to let that slide, but in practice most won't to prevent confusion (is what I read).理论上,管理员可以选择让那个滑动,但在实践中大多数不会防止混淆(这是我读到的)。

    I want:我想:

     console.log((/[^@]*/.exec(name)[0])+'@'+(/[^@]*$/.exec(name)[0]).toLowerCase);

    I have a working bit that is:我有一个工作位是:

     console.log((/[^@]*/.exec(name)[0])+'@'+name.substr(name.indexOf('@')+1).toLowerCase());

    The first one gives me:第一个给我:

     a@function toLowerCase(){ [native code] }

    And the second:第二个:

     a@b.c

    Which is fine, but the first one is prettier and less readable, which is great since no one else will be on it, ever.这很好,但第一个更漂亮,可读性更差,这很好,因为永远不会有人在上面。

    Is there some way to make the first one work?有没有办法让第一个工作? (Assigning it to let tmp= gives the same reply when log ( tmp ). (将其分配给let tmp=在记录( tmp )时给出相同的回复。

Replace代替

console.log((/[^@]*/.exec(name)[0])+'@'+(/[^@]*$/.exec(name)[0]).toLowerCase);

by经过

console.log((/[^@]*/.exec(name)[0])+'@'+(/[^@]*$/.exec(name)[0]).toLowerCase());

You could also do this你也可以这样做

const email = 'some.name@some_domain.com'
const [name, domain] = email.split('@')
console.log(`${name}@${domain}`);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM