Results 1 to 2 of 2
Thread: Regular Expression Help
- 06-23-2011, 08:51 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
Regular Expression Help
I want to have regex which shouldn't match if any whitespace, ", } comes just after {
example-
1. { abc} should not be matched as it has space after {
2. {"abc"} should not be matched as it has " just after {
3. {} and { } should not be matched as it doesn't have anything between {}
4. {mostRecentAffiliation|textonly='false'|urlonly='t rue'|affiliationtype='school'|linkToForMostRecentA ffiliationTags='member_list'} should be matched
5. {school|append=' class list'|linkToForAffiliationTags='classlist'} should be matched
6. <div class=\"color2 text2 customFont txtColor21 floatLeft\">HOTTEST</div>"
+ "<div class=\"floatLeft redArrow\"></div>"
+ "<div class=\"floatLeft txtColor21\">"
+ "<a href=\"{mostRecentAffiliation|textonly='false'|url only='true'|affiliationtype='school'|linkToForMost RecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\"> Check Your Class List</a> | <a href=\"{mostRecentAffiliation|textonly='false'|url only='true'|affiliationtype='school'|linkToForMost RecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\">See Other Profiles</a>"
+ "</div>
it should pick {mostRecentAffiliation|textonly='false'|urlonly='t rue'|affiliationtype='school'|linkToForMostRecentA ffiliationTags='member_list'} twice
Please let me know if you can find something to handle this
I am also trying but somehow something is missing.
I have junit test case as
If this test passes then uncomment the bottom code and comment these two linesJava Code:@Test public void checkTagPattern() { Pattern tagPattern = Pattern.compile("\\{([^\\}]+)\\}");// \\{([^\\}]+)\\} String contentWithDuplicateTag = "<div class=\"color2 text2 customFont txtColor21 floatLeft\">HOTTEST</div>" + "<div class=\"floatLeft redArrow\"></div>" + "<div class=\"floatLeft txtColor21\">" + "<a href=\"{mostRecentAffiliation|textonly='false'|urlonly='true'|affiliationtype='school'|linkToForMostRecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\"> Check Your Class List</a> | <a href=\"{mostRecentAffiliation|textonly='false'|urlonly='true'|affiliationtype='school'|linkToForMostRecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\">See Other Profiles</a>" + "</div>"; String contentString1 = "<style> .hpOverlay{ opacity:0.5; }"; String contentString2 = "body.ie .hpOverlay{ filter: alpha(opacity=50); }"; String contentString3 = "<B>{school|append=' class list'|linkToForAffiliationTags='classlist'}</a></b>"; String contentString4 = "cacheImage : function(indx,cache){\r\n if(!indx) indx =0;\r\n\t if(flashBacksMV.cachedImages.length < largeImagesList.length) {\r\n\t if(!cache) {$(\"#FBCachedImages\").append(\"<img src=\\\"\"+flashBacksMV.nonCachedImages[indx]+\"\\\" style=\\\"width:534px;height:370px;border:0\\\">\")"; String contentString5 = "<a href=\"{mostRecentAffiliation|textonly='false'|urlonly='true'|affiliationtype='school'|linkToForMostRecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\"> Check Your Class List</a> | <a href=\"{mostRecentAffiliation|textonly='false'|urlonly='true'|affiliationtype='school'|linkToForMostRecentAffiliationTags='member_list'}\" class=\"link2 txtColor21\">See Other Profiles</a>"; String contentString6 = "<style> .hpOverlay{}"; String contentString7 = "<style> .hpOverlay{ }"; Matcher matcher1 = tagPattern.matcher(contentString1); Matcher matcher2 = tagPattern.matcher(contentString2); Matcher matcher3 = tagPattern.matcher(contentWithDuplicateTag); Matcher matcher4 = tagPattern.matcher(contentString3); Matcher matcher5 = tagPattern.matcher(contentString4); Matcher matcher6 = tagPattern.matcher(contentString5); Matcher matcher7 = tagPattern.matcher(contentString6); Matcher matcher8 = tagPattern.matcher(contentString7); assertFalse(matcher1.find()); assertFalse(matcher2.find()); assertFalse(matcher7.find()); assertFalse(matcher8.find()); assertTrue(matcher3.find()); assertFalse(matcher5.find()); assertTrue(matcher4.find()); assertTrue(matcher6.find()); // while (matcher4.find()) { // String group = matcher4.group(1); // assertEquals("school|append=' class list'|linkToForAffiliationTags='classlist'", // group); // } // while (matcher6.find()) { // String group = matcher6.group(1); // assertEquals( // "mostRecentAffiliation|textonly='false'|urlonly='true'|affiliationtype='school'|linkToForMostRecentAffiliationTags='member_list'", // group); // } }
assertTrue(matcher4.find());
assertTrue(matcher6.find());
Please help.
Thanks in advance.
NiketLast edited by Fubarable; 06-23-2011 at 09:44 PM. Reason: code tags added
- 06-24-2011, 04:56 PM #2
I'm not often using regexes, but when I do I use it to find something, not to tell me that the expression is not in it (and your proposed expression does something like that i.m.h.o: returning the part of the string that is not your expression).
So maybe you should find strings that contain some of your three sequences and then decide in code not to use them.
Or alternatively, tell me a regex that reports "not found" when there is "rain" in "grainforest", then I try to give your solution. (I admit I'm no regex-pro.)Last edited by Jodokus; 06-24-2011 at 05:05 PM. Reason: removing NO
No bug ever had to calculate its fitnessfunction.
Similar Threads
-
regular expression
By ehsansad in forum New To JavaReplies: 8Last Post: 03-18-2011, 02:23 PM -
Help with regular expression
By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM -
regular expression
By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 11:15 AM -
regular expression
By QkrspCmptPop in forum Advanced JavaReplies: 8Last Post: 01-20-2010, 03:55 AM -
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks