java regex help

From: Rick Venter (rick_venter_at_yahoo.com)
Date: 10/27/03


Date: 27 Oct 2003 11:43:27 -0800

I am trying to create a regular expression for matching a pattern with
a string enclosed in curly braces { } and not able to do that using
java.

For ex: if the String is
foo {bar} alpha {baz}:{bat} gamma

I need the strings:
{bar}
{baz}
{bat}

after the pattern matching

How do I do that ? Following is the code snippet and it is not
printing out anything. I think my regular expression pattern might be
wrong.

Can anyone help ?

protected static final String PARAMETER_REGEX =
"\\{\\[\\^\\{\\}\\]+\\}";

String originalString = "foo {bar} alpha {baz}:{bat} gamma";

Pattern p = Pattern.compile(PARAMETER_REGEX);
Matcher m = p.matcher(originalString);

while(m.find()) {
 System.out.println(matcher.group());
}



Relevant Pages

  • Re: array or with non-array
    ... David A. Black wrote: ... > matching an IO object to a pattern. ... > there *should* be an explicit, intervening string representation. ... This works pretty well for every pattern without anchors. ...
    (comp.lang.ruby)
  • Re: String Manipulation Alternatives to RegEx
    ... million bytes of text to search through, as using a regular expression is ... >I have string that is 2.5 million bytes long. ... > I tried using Regular Expressions to look for patterns and replace the> pattern found with a pre-defined text. ... > So I am looking for an alternative method as I've been told Regular> Expressions are expensive. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Search Ambiguous
    ... Suppose the pattern has multiple instances of '*', ... The starting point for matching frag2 depends on the accuracy of the match ... Function AmbiguousFindAndReturn(TextString As String, _ ...
    (microsoft.public.vb.general.discussion)
  • Re: Emoticon text parser
    ... That is very close to a regular expression already. ... Put it all together, in a string, which requires doubling the escapes: ... We can ease the pain with the COMMENT flag of Pattern; ... as Christian suggested instead of the commenting stuff. ...
    (comp.lang.java.programmer)
  • Re: [RCR] array or with non-array
    ... This requires the arg to be a String. ... I'm not sure how much more polymorphic one could get, unless one had every object present its .to_s representation for matching, which would not be good. ... The object has to match the pattern, and the patterns are descriptions of strings. ... # pos can go beyond the eof ...
    (comp.lang.ruby)