Problems with regular expressions.

Hi all.

I want to substitute within an xml file a string with the following structure:

Referencer="//@Model/@OwnedElement.0/@OwnedElement.1/@OwnedElement.0/@OwnedElement.1/@OwnedElement.33 ..."

where the dots mean that the string within the quotes may be repeated (separated by spaces) many times.

I've tried to match such expression with java regex, with no luck. I thought running

line.contains("Referencer=\"[^\"\\r\\n]*\"");

would return true, but it didn't.

Could anybody point me the right way?.

Thank you all in advance.

[585 byte] By [jpsilvaa] at [2007-10-3 2:09:46]
# 1

String.contains() treats its argument as a literal string, not a regex. If you want to use a regex to search for a substring within a larger string, you have to use Matcher.find().

Pattern p = Pattern.compile("Referencer=\"[^\"\\r\\n]*\"");

Matcher m = p.matcher(line);

if (m.find())

{

...

}

uncle_alicea at 2007-7-14 19:08:39 > top of Java-index,Java Essentials,New To Java...