Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



RegEx - verify content and size

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-02-2010
Member
 
Join Date: Dec 2009
Posts: 178
RegEx - verify content and size

Hello,
I need to check a string, it must contain an email whose maximum length is limited, the basic RegExp is
Code:
^ [a-zA-Z0-9 \ -] (1). [a-zA-Z0-9 \ -] (1) @ [a-zA-Z0-9 \. \ -] (1) . [az] (2,5) $
The problem is that I do not know how to control in the same regular expression as the total size does not exceed 100 characters included. In fact what I need is a form of "AND" logic. I need it because i want to verify the content and size. If you know one then please do post back. Thanks in advance.
Reply With Quote
  #2  
Old 04-02-2010
Member
 
Join Date: Nov 2009
Posts: 520
Re: RegEx - verify content and size

Hello,
You can go out with the following regular expression.
Code:
^(?=.{ 1.100) $) [a-zA-Z0-9 \ -] (1). [A-zA-Z0-9 \ -] (1) @ [a-zA-Z0-9 \. \ -] (1). [az] (2,5) $
However, as stated in verbose it is best if possible to make a simple chain.length () and check the size. That would avoid adding to the regex and should be faster. First I will recommend you to test this in your code and if it is successful then it will be good for your code.
Reply With Quote
  #3  
Old 04-02-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: RegEx - verify content and size

Hi
Thank you for your response. I can not verify the size directly because I'm working on a function that checks each line of a file from a dozen online. This function takes the input file and a table containing a RegExp line of the file. The funny thing is that each line contains several fields. The line by line audit file with the RegExp works perfectly and is very powerful, my only problem is managing the email field.
Reply With Quote
  #4  
Old 04-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: RegEx - verify content and size

Hello,
This expression should be valid with the RE engine standard Java API. I suppose the engine jakarta does not bear the Lookaround. Which is the standard java RE engine are you using? If you know that then please post back. Because I do not think what you are doing will succeed. Currently I do not have a way round, but if I come to know one then i will post.
Reply With Quote
  #5  
Old 04-02-2010
Member
 
Join Date: Nov 2009
Posts: 344
Re: RegEx - verify content and size

Hello,
Lookaround No, I do not think you can get away with a single regexp. Maybe you should look for another engine. On the site of the regex lib Jakarta there is a link to the Project ORO which is compatible with Perl 5 (it seems to me that Lookaround appeared in perl 5), but I do not know what it's worth really. Edition after verification, I confirmed with OROIt should work. If you need you can try this and test.
Reply With Quote
  #6  
Old 04-02-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: RegEx - verify content and size

Hey,
Here is my code, please check it and if I am wrong somewhere, then please guide me.
Code:
Public class TestRegExp {
 
	Public static void hand(String[] args) {
		
		
		String str = "(?=[^;]{ 7.100);) [a-zA-Z0-9\\-_]{1,}\\. [a-zA-Z0-9\\-_] (1) @ [a-zA-Z0-9\\-_\\.]{1,}\\. [a-zA-Z] (2) ";;

String strTest = "31122001";

Perl5Compiler com = new Perl5Compiler();
Perl5Matcher mat = new Perl5Matcher();
Perl5Pattern p;
		try {
			p = (Perl5Pattern) com.compiles(str);
			if(mat.games(strTest, p)) {
				System.out.System.out.println("OK");
			} else {
				System.out.System.out.println("not OK");
			}
		} catch (MalformedPatternException e) {
			/ / TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "RegEx - verify content and size"
Thread Thread Starter Forum Replies Last Post
Verify password and regex Gunner 1 Software Development 5 17-02-2010 05:44 AM
Regex to verify email address Aaliya Seth Software Development 5 17-02-2010 03:50 AM
Regex to verify data Gunner 1 Software Development 5 16-02-2010 05:27 AM
Verify the content of the textbox with multiple buttons on Form Gadhadhar Software Development 5 23-01-2010 02:19 PM
Increase and Decrease Web Browser's Content size In a Second! FaMe FacToR Tips & Tweaks 2 06-02-2009 12:01 AM


All times are GMT +5.5. The time now is 07:42 AM.