aspose file tools*
The moose likes Java in General and the fly likes Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression" Watch "Regular Expression" New topic
Author

Regular Expression

Jay Jawalkar
Greenhorn

Joined: May 05, 2010
Posts: 10
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

Joined: Aug 16, 2005
Posts: 14103
    
  16

So, what did you answer to those questions yourself?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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 [.]


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jay Jawalkar
Greenhorn

Joined: May 05, 2010
Posts: 10
Please any body answer my question its urgent ...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41465
    
  51
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.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Jay Jawalkar wrote:its urgent ...

Please EaseUp.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression