How do I get rid of xml tags but not when the tag has copyright in it?

I tried this but it does not seem to do anything:
temp_string=temp_string.replaceAll("\\<.*?(!copyright)\\>", "");An example of this is that if I have: <meta name ="copyright" > I do not want to get rid of the tag. In other words, I do not want to get rid of any tags that have the word "copyright" in them, but I want to get rid of all other tags.
Edited by: setaret2004 on Dec 16, 2008 4:11 PM

setaret2004 wrote:
Also if I want to include license as well do I just do: str = str.replaceAll("<(?![^<>]*(copyright|license))[^<>]*>", ""); Is that correct?Yes, you can do the same thing with all three regexes. Now, explanations:
"<(?![^<>]*copyright)[^<>]*>" This regex does one lookahead, scanning forward for the word "copyright" before beginning the actual match. It's a negative lookahead, so if the word is seen, the lookahead fails and so does the overall match. If the lookahead succeeds, the match position is returned to where the lookahead started and the real matching begins.
A naïve approach would use ".&#x2A;" or ".&#x2A;?" in the lookahead, but then it would be free to scan past the end of the tag and find the word in the next tag or halfway through the document; lookaheads are slippery that way. But I used "[<>]&#x2A;", so once it reaches the closing ">" it stops scanning.
That means, for every successful match the regex scans the whole tag twice--once for the lookahead and once "for reals". That won't be a problem in most cases, but if you're matching many large chunks of text, performance could suffer. Each of the other regexes only traverses the tag once. "<(?:(?!copyright)[^<>])*>" This one steps through the text one character at a time, at each position doing a negative lookahead before matching the character. That sounds like a lot of work, but in the vast majority of cases the lookahead will only have to look at one character before yielding.
"<(?:(?!copyright|[<>]).)*>" This is basically the same as the second regex, but it does all the real work in the lookahead. I don't recommend it; it's less readable and probably less efficient than the second regex. But both the second and third regexes can be made more efficient by using [possessive quantifiers|http://www.regular-expressions.info/possessive.html] (that whole site is highly recommended, by the way): "<(?:(?!copyright)[^<>])*+>", "");
"<(?:(?!copyright|[<>]).)*+>" The first regex can use a possessive quantifier, too, but not in the lookahead: "<(?![^<>]*copyright)[^<>]*+>"

Similar Messages

  • How do i get an itunes library from a phone when the computer has crashed and it needs to go on a new computer

    How do i get an itunes library from a phone when the computer has crashed and it needs to go on a new computer

    1) ensure iTunes is authorized for your iTunes store account(s)
    2) connect your device and right-click or control-click it in the iTunes Source list, then choose transfer purchases from the shortcut menu that appears.
    3) sync the device
    iTunes will wipe the iPhone but, since you transferred your purchases in the previous step, your content will be in your library and you can re-populate the iPhone with it.
    above works for purchases from the iTunes store. for everything else, check out this post by Zevoneer.

  • How can I get rid of that irritating contact/favorites across the top of the home screen?

    How can I get rid of that irritating contact/favorites across the top of the home screen?

    Actually, that's not on the Home screen, it is on the multitasking or App Switcher view so only shows up when you enter that mode (so I'm not to clear as to why it is so "irritating", but whatever).
    Settings app > Mail,Contacts,Calendars > scroll down to CONTACTS section] > Show in App Switcher

  • How can I get rid of those infuriating banners just beneath the Search window?

    How can i get rid of those infuriating banners just beneath the Search window?

    Change your home page to a non-firefox one. If you want google as your home page, do the following:<br><br>
    #Go to google.com<br><br>
    #Click the Firefox button, go to Options | Options | General.<br><br>
    #Make sure it says "Show My Home Page" in the dropdown menu at the top and then click the button called "Use Current Pages".<br><br>
    I can't think what Mozilla is trying to achieve by displaying that childish junk.

  • I can not change my iPad to the uk store as I have a balance of $0.73 from th us store , how do I get rid of it, it's not enough to buy anything either

    I can not change my iPad to the uk store as I have a balance of $0.73 from th us store , how do I get rid of it, it's not enough to buy anything either

    Click here and ask the iTunes Store staff to zero your account balance.
    (105261)

  • How do i get rid of my first apple id when i got the phone

    how do i get rid of my first apple id when i bought the phone

    I don't think this is the easiest way. Have you concidered creating a new account and just... ignoring the last one? If this idea is not to your liking, just simply ring up apple. From what I know, you cannot cancel and account, but, I think that apple might be able to.

  • How to apply an InDesign Paragraph Rule above, but not when first in column

    How do I apply a paragraph rule "above" but not when first in a column. In other words, the rule above will only run if it isn't the first paragraph in the column (even if it appears in a multi-column text frame).
    Before you jump the gun: Rule below will not solve that, for various reasons.
    Thanks much in advance.

    Aha! Apparently totally!
    Here a similar way to yours with an anchored block. Copy it and launch this simple regex. Easy with no headache! 

  • How do I update my iPhone 3G firmware but not to the latest version?

    How do I update my iPhone 3G firmware but not to the latest version?
    I currently am running 3.1 but would like to update it to the 4.1 version (not the latest 4.3 version). How do I do this? I have already gone online and downloaded the 4.1 firmware for iPhone 3G but not sure how to install it. I unzipped the file then tried to do the Shift>Update trick but none of the downloaded files could be selected. Am I doing something wrong?

    There is no official way to do what you want, that's why the files can't be selected. iOS 4.2.1 is the last officially signed firmware available for your phone. If you want to install any other firmware you'll have to go elsewhere for instructions as such cannot be discussed here, per this forum's terms of use, sorry.

  • I have several ipod nanos. i can sync one, but since i connected the ipad 2 I am getting an error on two of them, it says cannot sync, error 13019. the loaded songs show on the computer (on the ipods), but not when the ipod is plugged off the usb

    i have several ipod nanos. i can sync one, but since i connected the ipad 2 I am getting an error on two of them, it says cannot sync, error 13019. the loaded songs show on the computer (on the ipods), but not when the ipod is plugged off the usb. Any answers? please

    You can sync your iPod with multiple computers, but what can be synced is very limited.  See this article for more details.
    http://support.apple.com/kb/ht1202
    B-rock

  • How do I get rid of "do you want to allow the following program to make changes to this computer"?

    I recently installed Adobe Acrobat 8 Professional and every time I open a PDF file that is stored on my computer, I get a pop-up that asks "Do you want to allow the following program to make changes to this computer?".  How do I get rid of this?  I don't want to change my security settings, I just want to open pdf's without having to go through this step.
    I'm using Windows 7.

    Thanks for that good idea.  I checked the "properties" by right clicking on the AA8 icon and under "compatability" I noticed it had Windows XP (Service Pack 3).  Since I'm running Windows 7, I changed it to that and now I don't get that annoying pop-up!

  • How do I get rid of an ad that is underneath the toolbars at the top of the browser?

    There is an ad for the Harry Potter movies that is underneath the two tool bars at the top of my browser. How do I get rid of it and return to the default

    Hold the option key when emptying the trash
    Jerry

  • How can I get rid of that row of icons below the bookmarks, which has Startnow on the left and Twitter on the right?

    I sought help among the available articles. I was informed that right clicking on a vacant part of the toolbar would give me the option to delete or hide it. Doesn't seem to work with this one. In fact, right clicking anywhere on this row isn't working. If I right click the "startnow" icon, it takes me to that page. I really don't want this toolbar, as it wastes my desk space. How do I get rid of it?

    Do you see that toolbar in View > Toolbars or Firefox > Options if the menu bar is hidden?
    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    Use a compressed image type like PNG or JPG to save the screenshot and make sure that you do not exceed the maximum file size (1 MB).

  • How can I get rid of 14 e-mails that say "This message has no content."

    How can I get rid of 14 emails on my iPad Touch that say, "This message has no content."  Since I can't open them, neither can I delete them.

    - Try resetting the iPod:
    Reset iPod touch:  Press and hold the On/Off Sleep/Wake button and the Home
    button at the same time for at least ten seconds, until the Apple logo appears.
    - Can you delete them if you access them on another device?

  • How do I get rid of"Index of file:///C:/" as the opening page?

    Every time Mozilla is opened, the following file is displayed: Index of file:///C:/ How can I get rid of it and set up a different homepage?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    Do a malware check with some malware scanning programs on the Windows computer.<br />
    You need to scan with all programs because each program detects different malware.<br />
    Make sure that you update each program to get the latest version of their databases before doing a scan.<br /><br />
    *http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
    *http://www.superantispyware.com/ - SuperAntispyware
    *http://www.microsoft.com/security/scanner/en-us/default.aspx Microsoft Safety Scanner
    *http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
    *http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
    *http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
    See also:
    *"Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked

  • How To Get rid of Exponential format in datagridview when the number is very large

    When the number is very large like :290754232, I got 2.907542E +08. in datagridview cell
    I using vb.net , framework 2.0.
    how can I get rid of this format?
    Thanks in advance

    should I change the type of this column to integer or long ?
    The datagridview is binded to binding source and a list ( Of).
    Mike,
    I'll show you an example that shows the correct way to do this and a another way if you're stuck using strings in exponential format. The latter being the "hack way" I spoke about Friday. I don't like it, it's dangerous, but I'll show both anyway.
    In this example, I'm using Int64 because I don't know the range of yours. If your never exceeds Int32 then use that one instead.
    First, I have a DataGridView with three columns. I've populated the data just by creating longs starting with the maximum value in reverse order for 100 rows:
    The way that I created the data is itself not a great way (there's no encapsulation), but for this example "it'll do".
    Notice though that the third column (right-most column) isn't formatted at all. I commented out the part that does that so that I could then explain what I'm doing. If it works, it should look like the first column.
    The first column represents an actual Int64 and when I show the code, you can see how I'm formatting that using the DGV's DefaultCellStyle.Format property. That's how it SHOULD be done.
    The third column though is just a string and because that string contains a letter in it, Long.TryParse will NOT work. This is where the "hack" part comes in - and it's dangerous, but if you have no other option then ...
    You can see that now the third column matches the first column. Now the code:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    With DataGridView1
    .AllowUserToAddRows = False
    .AllowUserToDeleteRows = False
    .AllowUserToOrderColumns = False
    .AllowUserToResizeRows = False
    .AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine
    .ReadOnly = True
    .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    .MultiSelect = False
    .RowHeadersVisible = False
    .RowTemplate.Height = 30
    .EnableHeadersVisualStyles = False
    With .ColumnHeadersDefaultCellStyle
    .Font = New Font("Tahoma", 9, FontStyle.Bold)
    .BackColor = Color.LightGreen
    .WrapMode = DataGridViewTriState.True
    .Alignment = DataGridViewContentAlignment.MiddleCenter
    End With
    .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
    .ColumnHeadersHeight = 50
    .DataSource = Nothing
    .Enabled = False
    End With
    CreateData()
    End Sub
    Private Sub CreateData()
    Dim longList As New List(Of Long)
    For l As Long = Long.MaxValue To 0 Step -1
    longList.Add(l)
    If longList.Count = 100 Then
    Exit For
    End If
    Next
    Dim stringList As New List(Of String)
    For Each l As Long In longList
    stringList.Add(l.ToString("e18"))
    Next
    Dim dt As New DataTable
    Dim column As New DataColumn
    With column
    .DataType = System.Type.GetType("System.Int64")
    .ColumnName = "Actual Long Value (Shown Formated)"
    dt.Columns.Add(column)
    End With
    column = New DataColumn
    With column
    .DataType = System.Type.GetType("System.String")
    .ColumnName = "String Equivalent"
    dt.Columns.Add(column)
    End With
    column = New DataColumn
    With column
    .DataType = System.Type.GetType("System.String")
    .ColumnName = "Formated String Equivalent"
    dt.Columns.Add(column)
    End With
    Dim row As DataRow
    For i As Integer = 0 To longList.Count - 1
    row = dt.NewRow
    row("Actual Long Value (Shown Formated)") = longList(i)
    row("String Equivalent") = stringList(i)
    row("Formated String Equivalent") = stringList(i)
    dt.Rows.Add(row)
    Next
    Dim bs As New BindingSource
    bs.DataSource = dt
    BindingNavigator1.BindingSource = bs
    DataGridView1.DataSource = bs
    With DataGridView1
    With .Columns(0)
    .DefaultCellStyle.Format = "n0"
    .Width = 150
    End With
    .Columns(1).Width = 170
    .Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    .Enabled = True
    End With
    End Sub
    ' The following is what I commented
    ' out for the first screenshot. ONLY
    ' do this if there is absolutely no
    ' other way though - the following
    ' casting operation is NOT ADVISABLE!
    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
    Handles DataGridView1.CellFormatting
    If e.ColumnIndex = 2 AndAlso e.Value.ToString IsNot Nothing Then
    ' NOTE! The following is dangerous!
    ' I'm going to use coercion to force the
    ' string into a type long. TryParse will
    ' NOT work here. This can easily throw an
    ' exception if the string cannot be cast
    ' to a type long. I'm "depending on" the
    ' the string to cast. At the very least
    ' you might put this in a Try/Catch but
    ' that won't stop it from failing (if
    ' it doesn't work).
    Dim actualValue As Long = CType(e.Value.ToString, Long)
    Dim formattedValue As String = actualValue.ToString("n0")
    e.Value = formattedValue
    End If
    End Sub
    End Class
    Like I said, only use that hack way if there's no other option!
    I hope it helps. :)
    Still lost in code, just at a little higher level.

Maybe you are looking for

  • Grace period in Terms of payment

    Dear all, My requirement is this I want to give some grace period in Payment terms , how can I maintain grace period in the payment terms. For Exaample :- 30 days due net and addition 5 days  as grace days(total 35 days) Reply ASAP Regards, Murali

  • Can you make a HTTP GET request with JSC form element?

    It seems the form element in JSC make a HTTP POST request by default, but is it possible to make a HTTP GET request by the form element in JSC? (It is worth to mention here that HTTP GET request has its distinctive advantages like you can embed the p

  • MOVED: Display driver stopped responding and has recovered. MSI GTX 670 Power Edition

    This topic has been moved to Graphics Cards. https://forum-en.msi.com/index.php?topic=251843.0

  • Xlate count and connection count

    Can a firewall show more XLATE created than CONNECTIONS? Is that theoretically possible to have more XLATEs than the total number of connections?. the reason I am asking, that assuming a Cisco 5510 has have maximum 130,000 total connections, however

  • Missing "Last configuration change at" into the config

    On two Catalyst 3750 12.2.(25r) SE1 with the command "show run" I don't see the info: "Last configuration change at xx" "NVRAM config last updated at xx" I use the "normal command: service timestamps debug datetime localtime service timestamps log da