5 Replies Latest reply: Jul 23, 2007 1:48 AM by 800282 RSS

    About Regex Pattern Match?

    807605
      Hi all,
      i am getting the exception,

      java.util.regex.PatternSyntaxException: Illegal character range near index 47
      [* &Com::Vwr::Web::HTML::Embperl::Execute($app->include_file_name('header'),$app,
      ^
      at java.util.regex.Pattern.error(Pattern.java:1541)
      at java.util.regex.Pattern.range(Pattern.java:2128)
      at java.util.regex.Pattern.clazz(Pattern.java:2069)
      at java.util.regex.Pattern.sequence(Pattern.java:1598)
      at java.util.regex.Pattern.expr(Pattern.java:1558)
      at java.util.regex.Pattern.compile(Pattern.java:1291)
      at java.util.regex.Pattern.<init>(Pattern.java:1047)
      at java.util.regex.Pattern.compile(Pattern.java:785)
      at java.lang.String.replaceFirst(String.java:1630)
      at regexTestNB.processAttribute(regexTestNB_test.java:189)
      at regexTestNB.processSegment(regexTestNB_test.java:132)
      at regexTestNB.<init>(regexTestNB_test.java:85)
      at regexTestNB.main(regexTestNB_test.java:569)


      I am Reading the string :
      [* &Com::Vwr::Web::HTML::Embperl::Execute($app->include_file_name('header'),$app, "VWR.COM - VWR International Catalogs"); *]


      Here is MY Code:

      String regexforPerlAttribute = "\".*?\"";
                     Matcher perlMatcher = Pattern.compile(regexforPerlAttribute,Pattern.DOTALL|Pattern.CASE_INSENSITIVE).matcher(text);
                     String[] PerlPlaceHolder = new String[0];
                     String textwithStartPH = "";
                     int i = 0;
                     while(perlMatcher.find()){
                          String firstPH = text.substring(index,perlMatcher.start());
                          PerlPlaceHolder[i] = firstPH;
                          i ++ ;
                          textwithStartPH = text.replaceFirst(firstPH, PLACEHOLDER);
                          String attVal = perlMatcher.group();
                          textwithStartPH = textwithStartPH.concat(attVal);
                          //constructSegments(attVal,writer);
                          index = perlMatcher.end();
                     }


      It shows exception at $app-> character

      I am reading the value between double quotes.
      Please help me.

      Thanx,
      Vinayak

      Message was edited by:
      VinuRocks

      Message was edited by:
      VinuRocks
        • 1. Re: About Regex Pattern Match?
          800282
          I'm unsure what it is you're trying to do.
          Something like this?
          String text = "[* &Com::Vwr::Web::HTML::Embperl::Execute($app->"+
                        "include_file_name('header'),$app, \"VWR.COM - VWR "+
                        "International Catalogs\"); *]";
          String regex = "\".*?\"";
          Matcher m = Pattern.compile(regex).matcher(text);
          while(m.find()){
            System.out.println(m.group());
          }
          • 2. Re: About Regex Pattern Match?
            807605
            yes. I am doing the same thing what you have understand.
            I want the value between " ", and replace the begining part of the text with word
            "PLACEHOLDERS". But i got exception on line
            textwithStartPH = text.replaceFirst(firstPH, PLACEHOLDER);

            Please help me.

            Thanx,
            Vinayak
            • 3. Re: About Regex Pattern Match?
              800282
              yes. I am doing the same thing what you have
              understand.
              I want the value between " ", and replace the
              begining part of the text with word
              "PLACEHOLDERS". But i got exception on line
              textwithStartPH = text.replaceFirst(firstPH,
              PLACEHOLDER);


              Please help me.

              Thanx,
              Vinayak
              Replace it with what exactly?
              What exception?
              • 4. Re: About Regex Pattern Match?
                807605
                this is the exception i am getting, and it shows some problem to '->' character ,

                java.util.regex.PatternSyntaxException: Illegal character range near index 47
                [* &Com::Vwr::Web::HTML::Embperl::Execute($app->include_file_name('header'),$app,

                at java.util.regex.Pattern.error(Pattern.java:1541)
                at java.util.regex.Pattern.range(Pattern.java:2128)
                at java.util.regex.Pattern.clazz(Pattern.java:2069)
                at java.util.regex.Pattern.sequence(Pattern.java:1598)
                at java.util.regex.Pattern.expr(Pattern.java:1558)
                at java.util.regex.Pattern.compile(Pattern.java:1291)
                at java.util.regex.Pattern.<init>(Pattern.java:1047)
                at java.util.regex.Pattern.compile(Pattern.java:785)
                at java.lang.String.replaceFirst(String.java:1630)
                at regexTestNB.processAttribute(regexTestNB_test.java:189)
                at regexTestNB.processSegment(regexTestNB_test.java:132)
                at regexTestNB.<init>(regexTestNB_test.java:85)
                at regexTestNB.main(regexTestNB_test.java:569)


                Thanx,
                Vinayak
                • 5. Re: About Regex Pattern Match?
                  800282
                  this is the exception i am getting, and it shows some
                  problem to '->' character ,
                  That's two char's, not one.
                  But it's still not clear (to me) what it is you're replacing it with. Could you just drop the code and give an example in- and output String of what you're trying to do?