Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

String.replaceAll with regex?

Thread view: 
Tim De Roeck - 22 May 2004 19:54 GMT
Hi,

I have a string that contains an xml-document, and somewhere there is a
line: <!DOCTYPE office:document-content PUBLIC "-//OpenOffice.org//DTD
OfficeDocument 1.0//EN" "office.dtd">

Now, since I want my program to work with all versions of openOffice, this
line can change. But it will always begin with "<!DOCTYPE" and that's the
line I want to make dissappear.

I've tried, but the only way to make it work, seems to be to use replaceAll
with the whole line as first argument. Is there a way to work with regex
like e.g. "<!DOCTYPE *>" ? I've been trying lots of things, but they don't
seem to work.

Thanx in advance!
Tim
Chris Smith - 22 May 2004 20:34 GMT
> I've tried, but the only way to make it work, seems to be to use replaceAll
> with the whole line as first argument. Is there a way to work with regex
> like e.g. "<!DOCTYPE *>" ? I've been trying lots of things, but they don't
> seem to work.

Try "<!DOCTYPE [^>]*>".  The pattern you gave only matches DOCTYPE
followed by spaces and a '>', but your real document contains other
characters after DOCTYPE and before the '>'.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Tim De Roeck - 23 May 2004 07:03 GMT
>> I've tried, but the only way to make it work, seems to be to use
>> replaceAll with the whole line as first argument. Is there a way to
[quoted text clipped - 4 lines]
> followed by spaces and a '>', but your real document contains other
> characters after DOCTYPE and before the '>'.

Do you have a link where there's more information on how to form these
regular expressions? Because it seems that "?" has it's own meaning in a
regex in java too. (I'm trying to change other things too) Thanx for the
help!

Tim
Andrew Thompson - 23 May 2004 07:33 GMT
> Do you have a link where there's more information on how to form these
> regular expressions?

Some info is hidden here..
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Tim De Roeck - 23 May 2004 12:51 GMT
><http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum>

thanx, I found this one that helped me along too. ;-)
<?xml version="1.0" encoding="UTF-8"?>

http://mindprod.com/jgloss/regex.html

greetz
Tim
Thomas Schodt - 23 May 2004 07:22 GMT
> Try "<!DOCTYPE [^>]*>".  The pattern you gave only matches DOCTYPE
> followed by spaces and a '>', but your real document contains other
> characters after DOCTYPE and before the '>'.

Or maybe "(?s)<!DOCTYPE .*?>".

(?s)    treat newline as any other character
.    match any character
*?    as few as possible ("reluctant" quantifier)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.