Re: [tw5] Re: Presenting: EditorMagic - the editor as an assistant

link to the discussion: https://groups.google.com/u/1/g/tiddlywiki/c/5Z_TwiVk8ls/m/szhhjUEIAgAJ

Mat, chat GPT will probably be a huge help to find regex expression :slight_smile:

Here’s one that match the example you gave:

\[\[([^\[\]]+)(?![\s\S]*\])

Try it : regex101: build, test, and debug regex

Explanation given by chat GPT:

To match the text immediately after [[ in a string, but only if it is not followed by ]] anywhere in the following text, you can use the following regular expression:

\[\[([^\[\]]+)(?![\s\S]*\]\])

This regular expression uses the following elements:

  • \[\[ matches two literal square brackets
  • ([^\[\]]+) matches one or more characters that are not square brackets ([^[]]) and captures the match as a group
  • (?![\s\S]*\]\]) is a negative lookahead assertion that matches a location in the string only if it is not followed by ]] anywhere in the following text ([\s\S]* matches any character, including newlines, zero or more times)

The regular expression will match the text immediately after the opening square brackets, provided that it is not followed by the closing square brackets anywhere in the following text. The matched text will be captured as a group, so you can access it using a capturing group (e.g. $1 in some programming languages).

For example, in the string There was a [[cat in a hat]] that [[sat on the mat the regular expression would match cat in a hat as a group.

3 Likes