ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:732回复:0

regex - can contain slash, just not at the start or end

楼主#
更多 发布于:2016-05-30 21:31
I am white-belt regex. I have the following regex which sort of works except allowing / Below "the below regex" I have listed my rules. also, i think my regex needs to be reversed because i want the match count to be greater than zero when invalid data is entered. Here is my regex so far which i think is still way off the mark: ^[/]|[=`~!@#$%^&*(){}\[\]:;"'<,>\.?]|//
 I wish the following cases to return a match count /  
hello  
hello/world  
hello/to/my/world  
 i wish the following cases to return a match count of zero. (blank_not_allowed)  
/hello  
hello/  
/hello/
hello.aspx  
hello/world.aspx  
hello//world
hello?  
 thanks
answer(解决方案):

This might work, although (phrase)+ isn't something I've tested (and would be happy to hear feedback on): /^((\/)|([a-z]+\/{0,1}[a-z]+)+)$/ I may have gotten carried away with the brackets...

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部