2道简单的题,考考你!

asdfasdf123 2007-05-08 10:38:06
1.实现把字符串org.apache.lucene转换成org/apache/lucene
2.如何判断一个字符串是否有效的email地址?
...全文
2468 62 打赏 收藏 转发到动态 举报
写回复
用AI写文章
62 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
<script language="javascript">
var emailStr=applyaddform.email.value;
var emailPat=/^(.+)@(.+)$/;
var matchArray=emailStr.match(emailPat);
if (matchArray==null)
{
alert("您输入的电子邮箱格式错误,请重新输入");
applyaddform.email.focus();
return false;
}
</script>

注:applyaddform为页面的form名称,email为一个文本框的name
YH555 2008-07-16
  • 打赏
  • 举报
回复
充当一下
Maozhj 2008-07-15
  • 打赏
  • 举报
回复
1楼的太牛X了!!汗死~
huoyutu 2008-07-15
  • 打赏
  • 举报
回复
<script language="java script1.2">
     <!-- start hiding
     function verifyAddress(obj)
     {
      var email = obj.email.value;
      var pattern =
/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
      flag = pattern.test(email);
      if(flag)
      {
       alert(“Your email address is correct!”);
       return true;
      }
      else
       {
        alert(“Please try again!”);
        return false;
        }
      }
     // stop hiding -->
    </script>
yangfengjob 2008-06-24
  • 打赏
  • 举报
回复
"org.apache.lucene".replaceAll(".","/");
H~~~ 2008-06-23
  • 打赏
  • 举报
回复
1.replace()
2.正则表达式
houyongbo03 2008-06-21
  • 打赏
  • 举报
回复
第一个用String的split方法
第二个用正则表达式
zmhot88 2008-06-16
  • 打赏
  • 举报
回复
太受打击了,我得好好学学
eddy520 2008-06-15
  • 打赏
  • 举报
回复
这一个跟那个转IP地址的.号转成,号的一样的吧
public class ed{
public static void main(String args[]){
String eddy="202.25.52.64";
eddy=eddy.replaceAll("\\.",",");
System.out.println(eddy);

}
都是要用转义字符的\\
eddy520 2008-06-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 micalorsoftware 的回复:]
str.replaceAll( ". ", "/ ");
str.matches( " ");
[/Quote]



你第一个要用转义的吧。应该是这样的str.replaceAll("\\.","/"); right!
kldxzzhc2 2008-05-27
  • 打赏
  • 举报
回复
傻逼,有问题就问,别说考考大家
第一个,用String类的split如果你发现"."当分隔符很不爽,或者说有异常那是因为.是政则表达式的元字符,需要二重转义"\\."

第二个,用正则表达式


什么是正则表达式,去学习下Perl语言就知道了
wn10000neng 2008-05-20
  • 打赏
  • 举报
回复
2题都很简单,我可以自己写代码。
因为我们学校23点断网,写不完,
以后有机会再来写
Shine_Panda 2008-05-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 strawren 的回复:]
kevinliuu(@。@) ( ) 信誉:107
-----------------------
NB
[/Quote]

信誉分是怎么看的啊?
FeelyourBreath 2008-05-12
  • 打赏
  • 举报
回复
不错。
lihuyi5203 2008-05-11
  • 打赏
  • 举报
回复
str.replaceAll( ". ", "/ ");
可以吗??
oldseasoul 2008-05-07
  • 打赏
  • 举报
回复
http://commons.apache.org/validator/上有一个通用的 java验证框架。
有一个类可以用于验证email

/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package org.apache.commons.validator;

import org.apache.oro.text.perl.Perl5Util;

public class EmailValidator
{

public static EmailValidator getInstance()
{
return EMAIL_VALIDATOR;
}

protected EmailValidator()
{
}

public boolean isValid(String email)
{
if(email == null)
return false;
Perl5Util matchAsciiPat = new Perl5Util();
if(!matchAsciiPat.match("/^[\\000-\\177]+$/", email))
return false;
email = stripComments(email);
Perl5Util emailMatcher = new Perl5Util();
if(!emailMatcher.match("/^(.+)@(.+)$/", email))
return false;
if(email.endsWith("."))
return false;
if(!isValidUser(emailMatcher.group(1)))
return false;
return isValidDomain(emailMatcher.group(2));
}

protected boolean isValidDomain(String domain)
{
boolean symbolic = false;
Perl5Util ipAddressMatcher = new Perl5Util();
if(ipAddressMatcher.match("/^\\[(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})\\]$/", domain))
return isValidIpAddress(ipAddressMatcher);
Perl5Util domainMatcher = new Perl5Util();
symbolic = domainMatcher.match("/^[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+(\\.[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+)*\\s*$/", domain);
if(symbolic)
return isValidSymbolicDomain(domain);
else
return false;
}

protected boolean isValidUser(String user)
{
Perl5Util userMatcher = new Perl5Util();
return userMatcher.match("/^\\s*(([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]|')+|(\"[^\"]*\"))(\\.(([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]|')+|(\"[^\"]*\")))*$/", user);
}

protected boolean isValidIpAddress(Perl5Util ipAddressMatcher)
{
for(int i = 1; i <= 4; i++)
{
String ipSegment = ipAddressMatcher.group(i);
if(ipSegment == null || ipSegment.length() <= 0)
return false;
int iIpSegment = 0;
try
{
iIpSegment = Integer.parseInt(ipSegment);
}
catch(NumberFormatException e)
{
return false;
}
if(iIpSegment > 255)
return false;
}

return true;
}

protected boolean isValidSymbolicDomain(String domain)
{
String domainSegment[] = new String[10];
boolean match = true;
int i = 0;
Perl5Util atomMatcher = new Perl5Util();
while(match)
{
match = atomMatcher.match("/([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+)/", domain);
if(match)
{
domainSegment[i] = atomMatcher.group(1);
int l = domainSegment[i].length() + 1;
domain = l < domain.length() ? domain.substring(l) : "";
i++;
}
}
int len = i;
if(len < 2)
return false;
String tld = domainSegment[len - 1];
if(tld.length() > 1)
{
Perl5Util matchTldPat = new Perl5Util();
return matchTldPat.match("/^([a-zA-Z]+)$/", tld);
} else
{
return false;
}
}

protected String stripComments(String emailStr)
{
String input = emailStr;
String result = emailStr;
String commentPat = "s/^((?:[^\"\\\\]|\\\\.)*(?:\"(?:[^\"\\\\]|\\\\.)*\"(?:[^\"\\\\]|I111\\\\.)*)*)\\((?:[^()\\\\]|\\\\.)*\\)/$1 /osx";
Perl5Util commentMatcher = new Perl5Util();
for(result = commentMatcher.substitute(commentPat, input); !result.equals(input); result = commentMatcher.substitute(commentPat, input))
input = result;

return result;
}

private static final String SPECIAL_CHARS = "\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177";
private static final String VALID_CHARS = "[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]";
private static final String QUOTED_USER = "(\"[^\"]*\")";
private static final String ATOM = "[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+";
private static final String WORD = "(([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]|')+|(\"[^\"]*\"))";
private static final String LEGAL_ASCII_PATTERN = "/^[\\000-\\177]+$/";
private static final String EMAIL_PATTERN = "/^(.+)@(.+)$/";
private static final String IP_DOMAIN_PATTERN = "/^\\[(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})\\]$/";
private static final String TLD_PATTERN = "/^([a-zA-Z]+)$/";
private static final String USER_PATTERN = "/^\\s*(([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]|')+|(\"[^\"]*\"))(\\.(([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]|')+|(\"[^\"]*\")))*$/";
private static final String DOMAIN_PATTERN = "/^[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+(\\.[^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+)*\\s*$/";
private static final String ATOM_PATTERN = "/([^\\s\\000-\\037\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]\\177]+)/";
private static final EmailValidator EMAIL_VALIDATOR = new EmailValidator();

}


/*
DECOMPILATION REPORT

Decompiled from: D:\workspace\Validate\lib\commons-validator-1.3.1.jar
Total time: 125 ms
Jad reported messages/errors:
Exit status: 0
Caught exceptions:
*/
maojianfe 2008-05-07
  • 打赏
  • 举报
回复
刚刚走上java这条路
其实我也不会
这个是正解吧?
String input = ...

//First
System.out.println(input.replaceAll("\\.","/"));

//Second
System.out.println(Pattern.compile("^([\\w-\\.]+)@[\\w-.]+(\\.?[a-zA-Z]{2,4}$)").matcher(input).matches());

^([\\w-\\.]+)@[\\w-.]+(\\.?[a-zA-Z]{2,4}$)这个是正则表达式吗?不懂什么意思!
胡矣 2007-10-21
  • 打赏
  • 举报
回复

1.把.替换成/就行了
String a="org.apache.lucene";
a=a.replace(".", "/");
System.out.println(a);
2.简单一点的方法是查看是否有@,如有则@后是否有. 这种方法不是很准确.
String a="dasfds@fds.com";
if(a.indexOf("@")!=-1&&a.indexOf(".",a.indexOf("@"))!=-1){
System.out.println("合法");
}
else
System.out.println("无效");
vitas826 2007-10-20
  • 打赏
  • 举报
回复
忘记回答了.
第一个不说了.
第二个用JavaScript实现如下.
function checkEmail(str)
{
var ref=/^[\w]{1,}@[\w]{1,}\.[\w]{1,}$/;
if(!return ref.test(str)){
alert("格式错误");
}
}
vitas826 2007-10-20
  • 打赏
  • 举报
回复
我见识了,终于知道为什么很多人找不到工作了.
原因不在于别人 在于你们自己.
正则表达式你说不会也就算了,借口也很简单,可以现查文档现用.
但是最基础的replaceAll方法不会,我真替那几个人悲哀.
还是转行吧,这行业不适合你.

你只会越走越没信心.
加载更多回复(38)

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧