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
在Java中使用连字符提取模糊的电子邮件_Java_Regex_Obfuscation - Fatal编程技术网

在Java中使用连字符提取模糊的电子邮件

在Java中使用连字符提取模糊的电子邮件,java,regex,obfuscation,Java,Regex,Obfuscation,我想提取一个用连字符模糊的电子邮件地址,格式为:f-o-o-@-e-x-a-m-p-l-e--c-o-m 到目前为止,我所做的是: String email = "f-o-o-@-e-x-a-m-p-l-e-.-c-o-m"; Pattern p = Pattern.compile("((\\w-)+)@-((\\w-)+)\\.-((\\w-){1,}\\w{1,6})"); Matcher m = p.matcher(email); while (m.find()) { emai

我想提取一个用连字符模糊的电子邮件地址,格式为:f-o-o-@-e-x-a-m-p-l-e--c-o-m

到目前为止,我所做的是:

String email = "f-o-o-@-e-x-a-m-p-l-e-.-c-o-m";

Pattern p = Pattern.compile("((\\w-)+)@-((\\w-)+)\\.-((\\w-){1,}\\w{1,6})");
Matcher m = p.matcher(email);

while (m.find()) {
    email = email.replace("-", "");
}

System.out.println(email);

但我想知道,如果电子邮件已经有一个连字符-例如:foo with-hyphen@example.com或foo@example-如果theos的邮件以上述方式混淆,我的代码将无法工作。我该怎么解决这个问题呢?

在我看来,您只需删除每一个连字符,就可以了?我的意思是删除字符串中奇数索引处的连字符


我假设连字符两边都用连字符填充,这样原始连字符就不会丢失,如果不是这样的话,如果它们没有以相同的格式保存,也就是e--x--a--m--p--l。。。其中实际字符串是e-x-a-m-p-l-…

请尝试以下示例

string email = "e-x-a-m-p-l-e-@-e-x-a-m-p-l-e---p-l-a-c-e-.-o-r-g";
string accum = "";
int index = 0;
int count = email.Count;
while (index < count)
{
    accum += email[index];
    index++;
    if (index < count)
    {
        if(email[index] != '-')
        {
            NOT_A_HYPHEN_ERROR;
        }
    }
    index++;
}

类似于Jesus Ramos的解决方案,但如果您输入的字符串格式不正确,则会发出警告。

听起来像您想要的是:

String email = "f-o-o-@-e-x-a-m-p-l-e-.-c-o-m";
email = email.replaceAll("(.)-", "$1");
System.out.println(email);

这个。模式匹配任何字符,而\w仅匹配数字和字母。

如果在“模糊处理”破坏原始源之前电子邮件中包含连字符,并且无法再次提取它。是否删除了所有连字符,或是在任一侧加上连字符?是否有人能解释所有否决票的来源?四次否决票,没有任何评论来解释为什么我觉得有点不对劲。@home-在你说什么东西是不可解决的之前,你可能想检查一下答案。@home:OP确实指定了编码算法。它在每个先前存在的字符之间插入一个连字符。它并没有被准确地拼写出来,但如果你真的读了上面写的内容,它是非常清楚的。我想我这几天脑子里有C。然而,转换应该是微不足道的,留给读者作为练习。