首页 > 编程知识 正文

java字符串分析正则表达式,js正则表达式匹配数字和字母

时间:2023-05-06 20:10:08 阅读:31939 作者:851

iamtryingtocheckwhetherapasswordisalphanumericornotusingregex

butiamnotgettingtheresultiexpect.whatistheproblemwiththebelowcode?

booleanpasswordonlyalphanumericcheck=false;

patternpatternalphanumericcheck=pattern.com pile (' pgddlca-za-z0-9 ) $ ' );

matchermatcheralphanumericcheck=patternalphanumericcheck.matcher (log in.get password () );

if (matcheralphanumericcheck.find ()

passwordonlyalphanumericcheck=true;

Thanks for help

youneedtoaddaquantifierthatsuitsyourrequirements : *-0 ormoreoccurrencesor-1 ormoreoccurrences.youcanalsoomitthe ^ and

booleanpasswordonlyalphanumericcheck=false;

if(login.getpassword ().matches([a-za-Z0-9]* ) )

passwordonlyalphanumericcheck=true;

To match all Unicode letters,usep{l}class(andperhaps,p{M} to match diacritics ) 3360((p{l}p )

whatisthedifferencebetweenlogin.get password ().Matches ) ' [0-9a-za-z]* '; and login.getPassword ().matches([0-9a-za-z] );

the.Matches([0-9a-za-z] ) willonlyreturntrueifthewholestringcontainsjust1digitor letter.the * in (0- 9a-zing

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。