Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Regular expression help

  • 13-06-2007 04:04PM
    #1
    Registered Users, Registered Users 2 Posts: 1,653 ✭✭✭


    Hi - Can someone please give me a regular expression for the following:

    Matches strings which start with

    My name is Mark

    but do not include

    and I live in Dublin


Comments

  • Registered Users, Registered Users 2 Posts: 950 ✭✭✭jessy


    what language are you using? have you made an attempt at this already?


  • Closed Accounts Posts: 97 ✭✭koloughlin


    Here's a perl regex that I think does this
    /^My name is Mark(?!.*and I live in Dublin)/
    


  • Registered Users, Registered Users 2 Posts: 1,653 ✭✭✭m_stan


    I'm actually just doing a big find and replace in Dreamweaver on an XML file.

    What I ideally need to do is replace any of the following

    My name is Mark and I am Irish and have blue eyes
    My name is Mark and I am male and have size 10 feet
    My name is Mark and I am tired and want to sleep

    with

    My name is Mark and I live in Dublin (followed by the rest of the original string after the 'Mark')

    Does that make sense ? Any help very much appreciated. This file is big with over 3000 matches to replace so I want to avoid doing this by hand.


  • Closed Accounts Posts: 97 ✭✭koloughlin


    Ok, then this will probably do that in perl
    #!/usr/bin/perl -w
    
    while(<>) {
       s/^My name is Mark(?!.*and I live in Dublin)/My name is Mark and I live in Dublin/; {
          print;
       }
    }
    


  • Registered Users, Registered Users 2 Posts: 950 ✭✭✭jessy


    so your not trying to develope an application or anything, you just want to save some time in updating an xml file which cantains a large amount of text? a once off update?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,653 ✭✭✭m_stan


    Gottit ! Thanks for your help. Very relieved not to have to do all this manually !!!


Advertisement