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.

Regex search/replace

  • 04-11-2007 02: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,652 ✭✭✭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