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

Regex search/replace

Options
  • 04-11-2007 2:30pm
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    Hi all, I'm trying to get my head around regular expressions but it's proving difficult. I was hoping someone would save me many times and help me out here:
    <img src="/images/F.gif" style="margin-right: -25px; padding: 0;" alt="F" />
    

    that "F" could be any letter, and I want to search and replace that whole <img> thing with just "F" (or whatever letter there is).

    Help please :D


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    $ echo '<img src="/images/F.gif" style="margin-right: -25px; padding: 0;" alt="F" />' | sed 's/.* alt="\([a-zA-Z]\)".*/\1/'
    F
    
    This extracts the character in the 'alt' part.

    What language are you trying to do this in? The regex syntax will be similar for most languages.


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Thanks got it sorted, I was trying to use %1 as a backreference but in PHP it's \\1


Advertisement