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

Regular Expression problem

  • 26-08-2009 12:07am
    #1
    Registered Users, Registered Users 2 Posts: 360 ✭✭


    Hi,

    I need to search a document for any length of text surrounded by square braces, basically [something like this] and [this] including the square braces, i'm not really familiar with regular expressions but i've been told i could do this with them, can anyone help???


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Get a lump of the sample text and use something like Expresso to build it (http://www.ultrapico.com/Expresso.htm). You can also use Regulazy by Roy Osherove (http://www.osherove.com/tools)


  • Closed Accounts Posts: 20 boars.ie


    $ perl -ne 'while (/(\[[^]]*])/g) {print "$1\n";}' < /etc/lftp.conf | head -5
    [\e[1;30m\]
    [\[\e[0;34m\]
    [\e[1m\]
    [\e[37m\]
    [\e[30m\]

    Note, that it does not properly detect nesting.
    Neither does it support multiline strings (but it is less related to regex itself)


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    It'd be worth reading the basics of regex as well:

    http://www.regular-expressions.info/


  • Registered Users, Registered Users 2 Posts: 3,721 ✭✭✭E39MSport


    [crmadm@PRODUCTION] # cat wibble
    [ken was here]
    [was he?]
    yes he was
    [crmadm@PRODUCTION] # grep '^\[.*\]$' wibble
    [ken was here]
    [was he?]


  • Registered Users, Registered Users 2 Posts: 60 ✭✭asmith


    this should do it,
    \[.*?\]
    


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 360 ✭✭eddyc


    Wow thanks for the replies! I was able to get it sorted , cheers


Advertisement