smerny Posted August 7, 2012 Share Posted August 7, 2012 Currently have this regex pattern thats probably pretty bad as I am not a regex pro and have been trying to tweak on it to make it work for what I need: "^(^[a-z.{2}][^\\s][a-z|.{2}]*[.]*[a-z]*)([\\*]*)[\\[]*([^\\]]*)[\\]]*" and it is working for most cases... but not all, and I'm having difficulties Examples of what I want to pass would be: [*]".." [*]"blah" [*]"blah*" [*]"blah.blah" [*]"blah.blah*" [*]any of 2-5 with [@attrib=value] or [@attrib="value" and @attrib2="value2" and ...] appended to the end examples of what I don't want to pass would be: [*]"" [*]"." [*]" " [*]"..." [*]".blah" [*]"-blah" basically want ".." or a string of a-z that could include but not start with dots or dashes -that is optionally followed by a * -that is optionally followed by a list of attributes/values with groups being: 1) ".." or a string a-z including but not starting with dots/dashes 2) "*" or StringUtils.EMPTY if no match 3) the group of attributes or StringUtils.EMPTY if no match Quote Link to comment Share on other sites More sharing options...
smerny Posted August 7, 2012 Author Share Posted August 7, 2012 btw, at this point i'm not really concerned with the exact format of the attribute list (just capture anything within square brackets) I redid the main part like this: "^([a-z]+[a-z.\\-]*[a-z])([\\*]*)[\\[]*([^\\]]*)[\\]]*" and it seems to work (besides the ".." case)... this is what I want to do to add the ".." case: "^([\\.]{2})$ | ^([a-z]+[a-z.\\-]*[a-z])([\\*]*)[\\[]*([^\\]]*)[\\]]*" but that doesn't work ^([\\.]{2})$ - starts and ends with ".." | - or ^([a-z]+[a-z.\\-]*[a-z]) - starts with atleast one a-z char... can contain 0 or more a-z, dots, or dash... has an a-z char at the end ([\\*]*) - can have optional * [\\[]*([^\\]]*)[\\]]* - can have optional [ ] with content between Quote Link to comment Share on other sites More sharing options...
smerny Posted August 7, 2012 Author Share Posted August 7, 2012 i guess the "has an a-z char at the end" part isn't working either... i can see why i think (getting caught in the part before it) but not sure how to fix it so right now, the best i have is "^([a-z]+[a-z.\\-]*)([\\*]*)[\\[]*([^\\]]*)[\\]]*" but it doesn't find just ".." and it includes like "blah." for example, when it shouldn't Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 8, 2012 Share Posted August 8, 2012 I think you need to split your RegExp into its constituent parts, and re-examine what you're actually asking of it. Because right now the minimum required string for it to pass, is a single letter "a-z" with all of the rest being optional. That means that "blah." is indeed legal content, as you've allowed a period to be part of the first sub group (as long as there's at least one letter in front of it). Quote Link to comment Share on other sites More sharing options...
smerny Posted August 8, 2012 Author Share Posted August 8, 2012 that is fine, "blah" was one of the "Examples of what I want to pass would be" list. the problems i'm having is: but it doesn't find just ".." and it includes like "blah." for example, when it shouldn't in the second line, blah has a dot at the end... i want to prevent that.. as well as allow for just ".." Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 8, 2012 Share Posted August 8, 2012 I think you need to re-read my post again, as you clearly missed quite a bit of it. Quote Link to comment Share on other sites More sharing options...
smerny Posted August 8, 2012 Author Share Posted August 8, 2012 i guess i'm just not sure why you are repeating one of the issues i said that i am unable to solve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.