• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression

 
Jay Jawalkar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have one problem in regular expression. The problem was asked to me in an interview. The problem is as follows:-

Explain the following 2 regular expressions. Where would they be used? What potential problems do you foresee in using them?

1. ^[a-zA-Z0-9]+([_.-]?[a-zA-Z0-9]+)?@[a-zA-Z0-9]+([_-]?[a-zA-Z0-9]+)*([.]{1})[a-zA-Z0-9]+([.]?[a-zA-Z0-9]+)*$

2. ^[^<>&~\s^%A-Za-z\\][^A-Za-z%^\\<>]{1,25}$

Thanks in advance.

Regards,
Jay
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what did you answer to those questions yourself?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Jawalkar wrote:([.]{1})

Why oh why would anyone write that {1} there? Occurring only once is the default; quantifiers like ?, +, * and {n}, {n,} and {n,m} should be used to change that default occurrence count.

Also, for an exact occurrence of . you can use \. (escaped in Java strings to \\.) instead of [.]
 
Jay Jawalkar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please any body answer my question its urgent ...
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can it be urgent after the interview?

If you're familiar with regexps then you should be able to give it a shot. If you're not, then any answer given here will not make much sense, and you should start by working through a regexp tutorial.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Jawalkar wrote:its urgent ...

Please EaseUp.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic