I am using the java.util.regex.Matcher and java.util.regex.Pattern packages.
I am trying to parse an input string into tags and text (yes, I'll be looking at velocity soonish) and am having a bad brain day.
Text is what you think it is. Tags look like "${name}".
Here's my regex so far:
Pattern.compile("(\\$\\{([_a-zA-Z0-9]+)\\}){0,1}([^$]*)", Pattern.DOTALL)
This is supposed to say, "recognize zero or one tags, followed by a lot of text that doesn't include dollar signs."
Then I loop over the input string building a List of tag and text classes. Now I have a compiled template. It works most of the time :-/
The problems with that regexp are
1) It seems to eat '$' when they aren't associated with tags. For example, the string "The car cost $10000" would be recognized as two separate pieces of text with the '$' being eaten.
2) It seems 'nothing' matches this string, so the final result is always a null result - that is, a match is returned, but all the groups are null or zero-length strings.
I've gone around-and-around on this, when I fix one issue I make another. Any suggestions?
I am trying to parse an input string into tags and text (yes, I'll be looking at velocity soonish) and am having a bad brain day.
Text is what you think it is. Tags look like "${name}".
Here's my regex so far:
Pattern.compile("(\\$\\{([_a-zA-Z0-9]+)\\}){0,1}([^$]*)", Pattern.DOTALL)
This is supposed to say, "recognize zero or one tags, followed by a lot of text that doesn't include dollar signs."
Then I loop over the input string building a List of tag and text classes. Now I have a compiled template. It works most of the time :-/
The problems with that regexp are
1) It seems to eat '$' when they aren't associated with tags. For example, the string "The car cost $10000" would be recognized as two separate pieces of text with the '$' being eaten.
2) It seems 'nothing' matches this string, so the final result is always a null result - that is, a match is returned, but all the groups are null or zero-length strings.
I've gone around-and-around on this, when I fix one issue I make another. Any suggestions?