Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Regular expression help

Options
  • 13-06-2007 5:04pm
    #1
    Registered Users 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 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 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 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 Posts: 1,653 ✭✭✭m_stan


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


Advertisement