#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    4
    Rep Power
    0

    Smile Regex match; replacing with lowercase


    Hi

    I am using Geany text editor which has a built in regex for search terms and replace terms.
    I am open to using any tool available on Linux

    My matching regex is
    ([a-zA-Z])- ([a-zA-Z])-([a-zA-Z])

    This finds for example
    a-Z-B
    E-a-G
    h-r-T

    I wish to replace the same text with all lower case i.e
    a-z-b
    e-a-g
    h-r-t

    In Geany replacing the group is like this
    \1-\2-\3
    except that this will simply replace the match with what is already there.

    How do I match and then replace the same with lower case using Geany, or any other Linux tool.

    Thanks
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,024
    Rep Power
    9616
    Mere regular expressions can't do things like transform text to lowercase. You need support from whatever tool/language to do that; Perl, for example, can because it's part of the language.
    I don't know of any editors that support it as well. It's worth checking, though: probably a \l or \L.

    So that means an "other Linux tool". Like sed.
    Code:
    sed 's/([a-zA-Z])- ([a-zA-Z])-([a-zA-Z])/\L&/'
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Posts
    4
    Rep Power
    0

    Talking


    Originally Posted by requinix
    Mere regular expressions can't do things like transform text to lowercase. You need support from whatever tool/language to do that; Perl, for example, can because it's part of the language.
    I don't know of any editors that support it as well. It's worth checking, though: probably a \l or \L.

    So that means an "other Linux tool". Like sed.
    Code:
    sed 's/([a-zA-Z])- ([a-zA-Z])-([a-zA-Z])/\L&/'
    Thank you. That certainly sent me in the right direction.
    Here is the bash script I created. If anyone needs to do selective substitution of upper-case for lower-case here is how. Below script uses sed to do in file replacement.

    Code:
    #/bin/bash!
    sed -ie ':a;N;$!ba;s|<keybind key="\([A-Za-z]\)-\([A-Za-z0-9]\)-\([A-Za-z0-9]\)-\([A-Za-z0-9]\)|<keybind key="\L\1-\L\2-\L\3-\L\4|g' /home/user/Desktop/lubuntu-rc.xml
    sed -ie ':a;N;$!ba;s|<keybind key="\([A-Za-z]\)-\([A-Za-z0-9]\)-\([A-Za-z0-9]\)|<keybind key="\L\1-\L\2-\L\3|g' /home/user/Desktop/lubuntu-rc.xml
    sed -ie ':a;N;$!ba;s|<keybind key="\([A-Za-z]\)-\([A-Za-z0-9]\)|<keybind key="\L\1-\L\2|g' /home/user/Desktop/lubuntu-rc.xml
  6. #4
  7. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,024
    Rep Power
    9616
    By the way, \L uppercases everything after it - you only need the one just before \1, and it stays in effect until a \E (if present) or the end of the string.

IMN logo majestic logo threadwatch logo seochat tools logo