Regex help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marius Trælnes

    #1

    Regex help

    Hello!

    I have a file with following htmlt tags:

    .....can be anything before....
    <div id="SomeConfig" >
    some text, can be anything here, also any tag
    </div>
    .....can be anything after......

    I want to "cut" out the div which has an id attribute with config in its's
    value. In the above sample
    this would be:
    <div id="SomeConfig" >
    some text, can be anything here, also any tag
    </div>

    I try with this but it does not work:

    Dim re As Regex = New Regex("(<div id=.*?config.*? div>)",
    RegexOptions.Ig noreCase)
    Dim m As Match = re.Match(Text)
    Dim s As String = m.Value()

    Any suggestions?

    Marius


  • Rick Mogstad

    #2
    Re: Regex help

    try it with the regexoptions.Si ngleLine


    "Marius Trælnes" <marius.traelne snospam@nospamc 2i.net> wrote in message
    news:eCLstPcbFH A.1040@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hello!
    >
    > I have a file with following htmlt tags:
    >
    > ....can be anything before....
    > <div id="SomeConfig" >
    > some text, can be anything here, also any tag
    > </div>
    > ....can be anything after......
    >
    > I want to "cut" out the div which has an id attribute with config in its's
    > value. In the above sample
    > this would be:
    > <div id="SomeConfig" >
    > some text, can be anything here, also any tag
    > </div>
    >
    > I try with this but it does not work:
    >
    > Dim re As Regex = New Regex("(<div id=.*?config.*? div>)",
    > RegexOptions.Ig noreCase)
    > Dim m As Match = re.Match(Text)
    > Dim s As String = m.Value()
    >
    > Any suggestions?
    >
    > Marius
    >
    >[/color]


    Comment

    • Michael Persaud

      #3
      Re: Regex help

      I had a similar experience and the following modified block helped


      Dim regexp As Regex = New Regex("<div id=((.|\n)*?)co nfig</div>",
      RegexOptions.Ig noreCase)

      Dim str As String
      Dim objMatch As Match
      For Each objMatch In regexp.Matches( text)
      str = objMatch.ToStri ng()
      Next

      Hope this helps

      Michael


      "Marius Trælnes" <marius.traelne snospam@nospamc 2i.net> wrote in message
      news:eCLstPcbFH A.1040@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hello!
      >
      > I have a file with following htmlt tags:
      >
      > ....can be anything before....
      > <div id="SomeConfig" >
      > some text, can be anything here, also any tag
      > </div>
      > ....can be anything after......
      >
      > I want to "cut" out the div which has an id attribute with config in its's
      > value. In the above sample
      > this would be:
      > <div id="SomeConfig" >
      > some text, can be anything here, also any tag
      > </div>
      >
      > I try with this but it does not work:
      >
      > Dim re As Regex = New Regex("(<div id=.*?config.*? div>)",
      > RegexOptions.Ig noreCase)
      > Dim m As Match = re.Match(Text)
      > Dim s As String = m.Value()
      >
      > Any suggestions?
      >
      > Marius
      >
      >[/color]


      Comment

      Working...