Windows Vista Forums

regular expression help
  1. #1


    Stimp Guest

    regular expression help

    Hi all,

    given a string:

    " <img class='myclass' alt='my picture' src='image.jpg' /> "

    (where alt and src are changeable)

    how do I create the following string:

    " <div class='container'>
    <div class='inner'>
    <img class='myclass' alt='my picture' src='image.jpg' />
    <p>my picture</p>
    </div>
    </div> "

    (where the contents of <p></p> are the same as the image 'alt') ?




    I believe a regular expression would solve this but I'm not sure on the
    syntax.

    something like:

    regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    class='container'><div class='inner'><img class='myclass' alt='$1'
    src='$2' /><p>$1</p></div></div>")


    Any ideas? Thanks!



    --

    fiddlewidawiddum

      My System SpecsSystem Spec

  2. #2


    Evertjan. Guest

    Re: regular expression help

    Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:

    > Hi all,
    >
    > given a string:
    >
    > " <img class='myclass' alt='my picture' src='image.jpg' /> "
    >
    > (where alt and src are changeable)
    >
    > how do I create the following string:
    >
    > " <div class='container'>
    > <div class='inner'>
    > <img class='myclass' alt='my picture' src='image.jpg' />
    > <p>my picture</p>
    > </div>
    > </div> "
    >
    > (where the contents of <p></p> are the same as the image 'alt') ?
    >
    >
    > I believe a regular expression would solve this but I'm not sure on the
    > syntax.
    >
    > something like:
    >
    > regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    > class='container'><div class='inner'><img class='myclass' alt='$1'
    > src='$2' /><p>$1</p></div></div>")
    >
    >
    > Any ideas? Thanks!

    Please do not multipost


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

      My System SpecsSystem Spec

  3. #3


    Stimp Guest

    Re: regular expression help

    On Sat, 2 Aug 2008 Evertjan. <exjxw.hannivoort@xxxxxx> wrote:

    > Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:
    >

    >> Hi all,
    >>
    >> given a string:
    >>
    >> " <img class='myclass' alt='my picture' src='image.jpg' /> "
    >>
    >> (where alt and src are changeable)
    >>
    >> how do I create the following string:
    >>
    >> " <div class='container'>
    >> <div class='inner'>
    >> <img class='myclass' alt='my picture' src='image.jpg' />
    >> <p>my picture</p>
    >> </div>
    >> </div> "
    >>
    >> (where the contents of <p></p> are the same as the image 'alt') ?
    >>
    >>
    >> I believe a regular expression would solve this but I'm not sure on the
    >> syntax.
    >>
    >> something like:
    >>
    >> regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    >> class='container'><div class='inner'><img class='myclass' alt='$1'
    >> src='$2' /><p>$1</p></div></div>")
    >>
    >>
    >> Any ideas? Thanks!
    >
    >
    > Please do not multipost
    as I mentioned in .javascript .. this is a post relevant to the groups I
    have posted to since many people don't read both groups.

    Answers in other groups will be placed here.

    cheers.
    --

    fiddlewidawiddum

      My System SpecsSystem Spec

  4. #4


    Al Dunbar Guest

    Re: regular expression help


    "Stimp" <ren@xxxxxx> wrote in message
    news:slrng9991n.nnj.ren@xxxxxx

    > Hi all,
    >
    > given a string:
    >
    > " <img class='myclass' alt='my picture' src='image.jpg' /> "
    >
    > (where alt and src are changeable)
    >
    > how do I create the following string:
    >
    > " <div class='container'>
    > <div class='inner'>
    > <img class='myclass' alt='my picture' src='image.jpg' />
    > <p>my picture</p>
    > </div>
    > </div> "
    >
    > (where the contents of <p></p> are the same as the image 'alt') ?
    >
    >
    > I believe a regular expression would solve this but I'm not sure on the
    > syntax.
    >
    > something like:
    >
    > regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    > class='container'><div class='inner'><img class='myclass' alt='$1'
    > src='$2' /><p>$1</p></div></div>")
    >
    >
    > Any ideas? Thanks!
    I must be an irregular kind of guy, as I have never gotten into regular
    expressions. Here's how I would solve this one:

    input = "<img class='myclass' alt='my picture' src='image.jpg' />"
    alt = split(split(input,"alt='")(1),"'")(0)
    output = "<div class='container'>" _
    & vbnewline & "<div class='inner'>" _
    & vbnewline & input _
    & vbnewline & "<p>" & alt & "</p>" & suffix
    & vbnewline & "</div" _
    & vbnewline & "</div"

    /Al



      My System SpecsSystem Spec

  5. #5


    Evertjan. Guest

    Re: regular expression help

    Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:

    >>> Any ideas? Thanks!
    >>
    >>
    >> Please do not multipost
    >
    > as I mentioned in .javascript .. this is a post relevant to the groups I
    > have posted to since many people don't read both groups.
    >
    > Answers in other groups will be placed here.
    Already shown in the other group,
    and this shows you are wrong not to heed Netiquette.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

      My System SpecsSystem Spec

  6. #6


    Al Dunbar Guest

    Re: regular expression help


    "Stimp" <ren@xxxxxx> wrote in message
    news:slrng99auc.nnj.ren@xxxxxx

    > On Sat, 2 Aug 2008 Evertjan. <exjxw.hannivoort@xxxxxx> wrote:

    >> Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:
    >>

    >>> Hi all,
    >>>
    >>> given a string:
    >>>
    >>> " <img class='myclass' alt='my picture' src='image.jpg' /> "
    >>>
    >>> (where alt and src are changeable)
    >>>
    >>> how do I create the following string:
    >>>
    >>> " <div class='container'>
    >>> <div class='inner'>
    >>> <img class='myclass' alt='my picture' src='image.jpg' />
    >>> <p>my picture</p>
    >>> </div>
    >>> </div> "
    >>>
    >>> (where the contents of <p></p> are the same as the image 'alt') ?
    >>>
    >>>
    >>> I believe a regular expression would solve this but I'm not sure on the
    >>> syntax.
    >>>
    >>> something like:
    >>>
    >>> regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    >>> class='container'><div class='inner'><img class='myclass' alt='$1'
    >>> src='$2' /><p>$1</p></div></div>")
    >>>
    >>>
    >>> Any ideas? Thanks!
    >>
    >>
    >> Please do not multipost
    >
    > as I mentioned in .javascript .. this is a post relevant to the groups I
    > have posted to since many people don't read both groups.
    >
    > Answers in other groups will be placed here.
    Evertjan's comment is still valid. When you have a thread that has relevence
    to a small number of groups, the best way to handle it is to CROSSPOST
    rather than MULTIPOST. That way a reply in one group will be sent to all
    groups without you having to, redundantly and manually copy from one group
    to the other to try to keep them in synch.

    FYI, the reason that many of us find multiposting frustrating is that we
    often see one of the posts with no responses, and then spend a fair amount
    of time supplying an answer - only to find out that was a waste of time
    because someone already supplied the answer in another group.

    /Al



      My System SpecsSystem Spec

  7. #7


    Stimp Guest

    Re: regular expression help

    On Sat, 2 Aug 2008 Al Dunbar <AlanDrub@xxxxxx> wrote:

    >
    > "Stimp" <ren@xxxxxx> wrote in message
    > news:slrng9991n.nnj.ren@xxxxxx

    >> Hi all,
    >>
    >> given a string:
    >>
    >> " <img class='myclass' alt='my picture' src='image.jpg' /> "
    >>
    >> (where alt and src are changeable)
    >>
    >> how do I create the following string:
    >>
    >> " <div class='container'>
    >> <div class='inner'>
    >> <img class='myclass' alt='my picture' src='image.jpg' />
    >> <p>my picture</p>
    >> </div>
    >> </div> "
    >>
    >> (where the contents of <p></p> are the same as the image 'alt') ?
    >>
    >>
    >> I believe a regular expression would solve this but I'm not sure on the
    >> syntax.
    >>
    >> something like:
    >>
    >> regex.replace("<img class='myclass' alt='$1' src='$2' />","<div
    >> class='container'><div class='inner'><img class='myclass' alt='$1'
    >> src='$2' /><p>$1</p></div></div>")
    >>
    >>
    >> Any ideas? Thanks!
    >
    > I must be an irregular kind of guy, as I have never gotten into regular
    > expressions. Here's how I would solve this one:
    >
    > input = "<img class='myclass' alt='my picture' src='image.jpg' />"
    > alt = split(split(input,"alt='")(1),"'")(0)
    > output = "<div class='container'>" _
    > & vbnewline & "<div class='inner'>" _
    > & vbnewline & input _
    > & vbnewline & "<p>" & alt & "</p>" & suffix
    > & vbnewline & "</div" _
    > & vbnewline & "</div"

    I managed to get an answer to this.. thanks for the input though

    regex.replace(
    @"\<img\sclass\='myclass'\salt\='(.*?)'\ssrc\='(.*?)'\s\/\>",
    @"<div class='container'><div class='inner'><img class='myclass'
    alt='$1' src='$2' /><p>$1</p></div></div>");

    --

    fiddlewidawiddum

      My System SpecsSystem Spec

  8. #8


    Stimp Guest

    Re: regular expression help

    On Sat, 2 Aug 2008 Al Dunbar <AlanDrub@xxxxxx> wrote:

    >
    > Evertjan's comment is still valid. When you have a thread that has relevence
    > to a small number of groups, the best way to handle it is to CROSSPOST
    > rather than MULTIPOST. That way a reply in one group will be sent to all
    > groups without you having to, redundantly and manually copy from one group
    > to the other to try to keep them in synch.
    ah ok, I was under the impression that the replies went to only one of
    the groups .. which would seem counter to good "netiquette" as Evertjan
    likes to harp on about.

    Cheers for the constructive response

    --

    fiddlewidawiddum

      My System SpecsSystem Spec

  9. #9


    Evertjan. Guest

    Re: regular expression help

    Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:

    > On Sat, 2 Aug 2008 Al Dunbar <AlanDrub@xxxxxx> wrote:

    >>
    >> Evertjan's comment is still valid. When you have a thread that has
    >> relevence to a small number of groups, the best way to handle it is
    >> to CROSSPOST rather than MULTIPOST. That way a reply in one group
    >> will be sent to all groups without you having to, redundantly and
    >> manually copy from one group to the other to try to keep them in
    >> synch.
    >
    > ah ok, I was under the impression that the replies went to only one of
    > the groups .. which would seem counter to good "netiquette" as
    > Evertjan likes to harp on about.
    >
    > Cheers for the constructive response
    Ever heard of the word "sorry" if you make a mistake?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

      My System SpecsSystem Spec

  10. #10


    Stimp Guest

    Re: regular expression help

    On Sat, 2 Aug 2008 Evertjan. <exjxw.hannivoort@xxxxxx> wrote:

    > Stimp wrote on 02 aug 2008 in microsoft.public.scripting.vbscript:
    >

    >> On Sat, 2 Aug 2008 Al Dunbar <AlanDrub@xxxxxx> wrote:

    >>>
    >>> Evertjan's comment is still valid. When you have a thread that has
    >>> relevence to a small number of groups, the best way to handle it is
    >>> to CROSSPOST rather than MULTIPOST. That way a reply in one group
    >>> will be sent to all groups without you having to, redundantly and
    >>> manually copy from one group to the other to try to keep them in
    >>> synch.
    >>
    >> ah ok, I was under the impression that the replies went to only one of
    >> the groups .. which would seem counter to good "netiquette" as
    >> Evertjan likes to harp on about.
    >>
    >> Cheers for the constructive response
    >
    > Ever heard of the word "sorry" if you make a mistake?
    I will if you apologise for cross-posting the same reply twice

    --

    fiddlewidawiddum

      My System SpecsSystem Spec

regular expression help problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression help C# JP .NET General 3 02 Jun 2009
Regular Expression for ../ Ahmed .NET General 1 31 Oct 2008
Help with a regular expression PO VB Script 7 01 Oct 2008
Simple Regular Expression BJ PowerShell 6 30 Jan 2008
simple regular expression Ben PowerShell 2 19 Feb 2007