About Regex Pattern Match?

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 = 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

[2118 byte] By [VinuRocksa] at [2007-11-27 11:22:22]
# 1

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());

}

prometheuzza at 2007-7-29 14:54:30 > top of Java-index,Java Essentials,Java Programming...
# 2

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

VinuRocksa at 2007-7-29 14:54:30 > top of Java-index,Java Essentials,Java Programming...
# 3

> 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?

prometheuzza at 2007-7-29 14:54:30 > top of Java-index,Java Essentials,Java Programming...
# 4

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

VinuRocksa at 2007-7-29 14:54:30 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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?

prometheuzza at 2007-7-29 14:54:30 > top of Java-index,Java Essentials,Java Programming...