Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Regex search/replace

  • 04-11-2007 01: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, Registered Users 2 Posts: 6,704 ✭✭✭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