[PJUG Javamail] Silly Regex Question

Richard Johnson richardj at lingosys.com
Tue Jun 23 12:39:46 EDT 2009


Doh!  
 
Thanks, Zack.  :-)

________________________________

From: Zack Radick [mailto:zack at crc-corp.com] 
Sent: Tuesday, June 23, 2009 9:36 AM
To: Richard Johnson; javamail at pjug.org
Subject: Re: [PJUG Javamail] Silly Regex Question


Richard,

Since you are not matching an expression per se, I would recommend the
following for simplicity (as it seems to be what you are looking for):
foo[i].contains( "_TM" )

You could also do the following if it was more in line with your needs:
foo[i].endsWith( "_TM" )

--Zack

At 09:17 AM 6/23/2009, Richard Johnson wrote:


	Content-class: urn:content-classes:message
	Content-Type: multipart/related;
	         boundary="----_=_NextPart_001_01C9F41E.16A2CB20";
	         type="multipart/alternative"
	
	Hi all,
	 
	What's wrong with my logic and/or regex?
	 
	 
	I'm parsing a text file, extracting hopefully useful information
from a stated directory path.  I have a java pattern/regex that looks
like this:
	 
	String[] languages = new String[2];
	String[] foo = inputLine.split("\\\\");
	    Pattern langs = Pattern.compile("_TM");
	    int toggle = 0;
	    for(int i = 0; i < foo.length; i++)  {
	    Matcher m = langs.matcher(foo[i]);
	    if(m.find() && toggle == 0) {  //we have a language, but
it's the first one
	        toggle = 1;
	         languages[0] = fetchLanguageName(foo[i]);
	    }
	    else if(m.find() && toggle == 1)  {  //the second language
we find
	        toggle = 2;
	        languages[1] = fetchLanguageName(foo[i]);
	    }
	}
	Given an input line like this:
	    Translation Memory:
X:\2Checkout\2Checkout_English(U.S.)_TM\2Checkout_Chinese(Traditional)_T
M\cht_2CheckOut.tmw
	 
	It quite happily finds the first occurrence of '_TM' but then
fails to trigger on the second.  (i.e. we find English but not Chinese.)

	
	-- 
	
	Richard Johnson, Systems Architect<?xml:namespace prefix = o ns
= "urn:schemas-microsoft-com:office:office" />
	
	Lingo Systems
	
	<?xml:namespace prefix = st1 ns =
"urn:schemas-microsoft-com:office:smarttags" />15115 SW Sequoia Pkwy
#200
	
	Portland Oregon 97224
	
	richardj at lingosys.com
	
	http://www.lingosys.com <http://www.lingosys.com/> 
	
	voice  503-419-4889 or 800-878-8523
	
	FAX   503-419-4873
	
	 
	
	  
	 
	
	
	_______________________________________________
	Web Site - http://www.pjug.org/ 
	Javamail mailing list
	Javamail at pjug.org
	http://www.pjug.org/mailman/listinfo/javamail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pjug.org/pipermail/javamail/attachments/20090623/959a65c8/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 50186 bytes
Desc: 29911445.bmp
Url : http://www.pjug.org/pipermail/javamail/attachments/20090623/959a65c8/attachment.obj 


More information about the Javamail mailing list