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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Regex search/replace

  • 04-11-2007 1: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,571 ✭✭✭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