Menu

Find/replace regex help?

quickfold
2021-10-14
2021-10-25
  • quickfold

    quickfold - 2021-10-14

    Can someone help me do a find/replace with regular expressions in Freeplane? I know regex generally but not the Java implementation. I need to replace instances of @name + space with [@name] + space (for any name following the @). e.g.:

    @Smithspace

    with:

    [@Smith]space

    This is tricky for me because [ is a special character, and Java regex uses $ in the replace string rather than \1. My previous attempts failed. What do I put in the find field and replace field? Help appreciated!

     
  • quickfold

    quickfold - 2021-10-23

    Hello, helpful community members, can anyone provide information for me here?

     
    • Milavon

      Milavon - 2021-10-23

      Hi quickfold,

      this worked for me: (check "Regular expressions" box in both find and replace fields)
      Note: remove the double quotes from the search / replace string

      Find:
      "@(.*?)\s"

      Replace:
      "\[@$1\] "

       

      Last edit: Milavon 2021-10-23
      • quickfold

        quickfold - 2021-10-24

        Thank you! Do you know how to search/replace for a string that starts with a "@" and ends after the last letter or digit? So this one would work if the entire node is the replace string (with no space at the end), or if the string is followed by a space or punctuation mark.

        So "Also @Smith2000: this is true" would become "Also [@Smith2000]: this is true"

         
  • Milavon

    Milavon - 2021-10-25

    yes I tested this one, it works as requested

    Find:
    @([0-9a-zA-Z]*)

    Replace:
    \[@$1\]

    (it will surround the part starting with "@" followed only by letters and digits with
    the square brackets)

     
    👍
    1

    Last edit: Milavon 2021-10-25