Results 1 to 4 of 4

Thread: Find and replace pattern in complicated text file

  1. #1
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    Smile Find and replace pattern in complicated text file

    Here's a snippet of my text file:
    Code:
    | UnitEnteredLos()  ||  ||  ||  ||  unitID, teamID
    |-
    | UnitLeftRadar()  ||  ||  ||  ||  unitID, unitTeam
    |-
    | UnitLeftLos()  ||  ||  ||  ||  unitID, unitDefID, teamID
    How can I replace every function from the textfile so it becomes like this:
    Code:
    | [[/UnitEnteredLos()/]]  ||  ||  ||  ||  unitID, teamID
    |-
    | [[/UnitLeftRadar()/]]  ||  ||  ||  ||  unitID, unitTeam
    |-
    | [[/UnitLeftLos()/]]  ||  ||  ||  ||  unitID, unitDefID, teamID
    So I want each "functionName()" to become "[[/functionName()/]]".

    I have been using Gedit and I read the basics of regular expressions some time ago but can't remember much. Any suggestion is welcome.

  2. #2
    Join Date
    Aug 2005
    Beans
    14

    Re: Find and replace pattern in complicated text file

    Quote Originally Posted by Pithikos View Post
    Here's a snippet of my text file:
    Code:
    | UnitEnteredLos()  ||  ||  ||  ||  unitID, teamID
    |-
    | UnitLeftRadar()  ||  ||  ||  ||  unitID, unitTeam
    |-
    | UnitLeftLos()  ||  ||  ||  ||  unitID, unitDefID, teamID
    How can I replace every function from the textfile so it becomes like this:
    Code:
    | [[/UnitEnteredLos()/]]  ||  ||  ||  ||  unitID, teamID
    |-
    | [[/UnitLeftRadar()/]]  ||  ||  ||  ||  unitID, unitTeam
    |-
    | [[/UnitLeftLos()/]]  ||  ||  ||  ||  unitID, unitDefID, teamID
    So I want each "functionName()" to become "[[/functionName()/]]".

    I have been using Gedit and I read the basics of regular expressions some time ago but can't remember much. Any suggestion is welcome.
    Here's a very useful site to test regexp live : http://gskinner.com/RegExr/

    The pattern your are looking for is (\w*\(\)). See http://gskinner.com/RegExr/?2spah for your example live.

    V.

  3. #3
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    Re: Find and replace pattern in complicated text file

    Quote Originally Posted by V-Turn View Post
    Here's a very useful site to test regexp live : http://gskinner.com/RegExr/

    The pattern your are looking for is (\w*\(\)). See http://gskinner.com/RegExr/?2spah for your example live.

    V.
    Thanks! Though I am not sure how I am supposed to use the expression to replace the text..

  4. #4
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    Re: Find and replace pattern in complicated text file

    Problem solved.

    I just used Geany (seems it beats the heck out of Gedit).
    I just clicked on Seach>Replace and checked the "Use escape sequences"(it even has an option for regular expressions).

    Then I replaced "\n| " with "\n| [[/"
    and "() ||" with "()/]] ||".

    Worked as a charm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •