Help wanted with refactoring links

Thanks all,

I pulled the trigger and everything is good. The replace was better as [$2](dict://$1) as the second capture group was the lower case alias and most links were mid-sentence.

I’m stoked at the result - thank you all so much for the input. Happy days!

2 Likes

Did you use the regex from I-d-as? You’re aware that doesn’t pickup the case of [[_terms/Pyrexia]] where there are no alias?

Here is an explanation of your search:

  1. \[\[_terms/ – Matches the double brackets, and the text
  2. (.*) – A capture group catching anything
  3. | - When unescaped this is an alternator, and in your case all of my explanations above is the first alternator group, and all explanations below are the second alternator group
  4. (.*) - A capture group catching anything
  5. \]\] – An actual match on double brackets

So most matches in your image, is doing the alternating match of 4. and 5., that is capture anything before double brackets. This could be avoided by doing \| which instead means to actually match the specific character of | and not it’s (hidden?) alternator meaning.

1 Like

Sorry for still replying, but I wasn’t entirely satisfied with not preserving the case if no alias was given, so I kept pondering away. Explanation of regex.

The new search term is then: \[\[_terms\/(?:([^\]\|]*)\]\]|[^\]\|]*\|([^\]]*)\]\])
with replacement string: [$1$2](dict://$1$2)

I’m not particular fond of the doing $1$2 in the replacement, but the alternator operator and the entire setup of the regex assures that only one of them is set. The same reasoning applies to why the \]\] is duplicated as I needed both alternatives to fully match, to avoid mismatches. Could surely be optimised somehow, but my brain doesn’t see a clear solution just now to that issue. :face_with_spiral_eyes:

Regards,
Holroy

1 Like

Good stuff @holroy. It’s unlikely, but @jonr might have used the two pass technique (I did forget to add the underscore for the _terms folder name, but otherwise the technique may have worked reasonably well, but I’m not sure) :

Thanks for your explanations and commitment to getting things right. I too would be curious what ended up working.

@I-d-as: I just saw that his replacement string was the [$2](dict://$1) which refers to a secondary capturing group, so if that was his only run, it could indicate that he still got cases like the [[_term/Pyrexia]] floating around.

And just to clarify, I don’t really care whichever regex he uses, I just want him to actually get all of the changes he needs. But it’s always good to get a good response from the OP as to how he actually solved his question in the end.

1 Like

Hi,
Sorry I didn’t see these messages earlier. Thanks to everyone for their help.
Yes I used [$2](dict://$1) which solved the case issue as the aliases were all lower case.