Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex weirdness



"Todd O'Bryan" <email@hidden> wrote:

>Strangely, if tag = "<br/>"
>
>tag.replaceAll("(?<!<b/?|<br/?)>", "&gt;") is "<br/&gt;"
>
>but
>
>tag.replaceAll("(?<!<br/?|<b/?)>", "&gt;") is "<br/>"
>
>Can someone confirm that (a) this actually happens, and that (b) it's a bug
>and there's not some reason first regex should match while the second
>doesn't?

Can you explain why you think it's a bug?

If I understand regex correctly, and it's quite possible I don't in this
case, the differences in outcome are a consequence of the short-circuit |
operator and the order of the matching expressions. The first one to match
defines the extent of the non-capturing group.

Even in a little method, I wouldn't use regex replacement for doing *ML
tag-munging. I think it would be simpler to have a dictionary of tags,
which don't suffer replacement, and then walk through the text. The
immediate evidence suggests it would be more robust, comprehensible, and
maintainable, too.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.