Example regexp provided on the official tiddlywiki not working outside of it

Hi! I’m trying to write a regexp filter that will allow me to copy-paste various texts with the same formatting and convert them in tiddlers with their content distributed in fields. Probably more than a hundred of them, so it’s worth it for me to automatize the process instead of creating them manually.

During this, I stumbled upon a strange behaviour. One of the search-replace operator examples doesn’t seem to work on any wiki I use (I’m currently usind tiddloid lite for the project).

https://tiddlywiki.com/#search-replace%20Operator%20(Examples)

It is the sixth example, which says that:

To replace everything but a match using a regular expression and the multiline (m) flag:

\define myregexp2() ^(?!Unlike).*$

[[HelloThere]get[text]search-replace:gm:regexp<myregexp2>,[]]

It does in fact work over there, cutting out everything up to the “Unlike” lookahead match.

However, as you can see in this test tiddlywiki, it doesn’t work; the search-replace filter doesn’t affect its source in any way:

https://searchreplaceregexp.tiddlyhost.com/#Example

I’m experimenting but I can’t find what’s wrong here. My guess is that it has to do with the negative (!) lookahead somehow not being read.

G’day,

You have things in the wrong order ?

[[HelloThere]get[text]search-replace:gm:regexp<myregexp2>,[]]

EDIT: SCRATCH THAT!

What are you trying to do in that sample? I don’t think you have the right expression.

1 Like

Hi. I want to reproduce exactly the example provided on the official tiddlywiki. It works over there, but I can’t make it work.

1 Like

The sample at TiddlyWiki.com is using the HelloThere tiddler.

There is a whole bunch of content in that tiddler, and the regular expression gets just the one paragraph out of that Tiddler.

You have a small amount of text in a field.

Your example and the example at TiddlyWiki.com are a bit apples and oranges.

Create a tiddler called “New Tiddler”.

In it, put the following text:

Some text before.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Some text after.

Fix your filter so that things are in the proper order, and use the “New Tiddler” as the source in your filter:

{{{ [[New Tiddler]get[text]search-replace:gm:regexp<myregexp>,[]] }}}

  • "gm" must come before regexp !

The result will be just the paragraph:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

EDIT: ARG!!! I forgot to mention, setup the macro:

\define myregexp() ^(?!Lorem).*$

What I want to do in my project is:

  1. copy-paste a text from an external document to a tiddler’s field, called field1

  2. have a button with an action-setfield widget with a filter that replaces (deletes) everything from field1 but specific chunks of text.

The field1 content could be:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

The filter I want for that action-setfield widget should replace with blanks everything but the phrase sed do eiusmod (for example). This will have to be done for a number of action-setfield, each isolating specific words and putting them into fields.

Using the regexp provided in the official wiki examples doesn’t seem to work (that is, the negative lookahead).

The example you are using at TiddlyWiki.com does not match at all what you are wanting to do.

That example works outside of TiddlyWiki.com exactly as it does in TiddlyWiki.com

It is just the wrong example for the task you want to do.

What you really want to do, I suggest you create a new thread title something along the lines of How do I do this-thing with regexp in TiddlyWiki?

Will do that. I thought that I wanted to:

To replace everything but a match using a regular expression

So I was following that example. I’ll try and be more specific. Thank you for your time.

Try this:

\define myregexp() .*(sed do eiusmod).*
{{{ [[Example]get[writing]search-replace:gm:regexp<myregexp>,[$1]] }}}

The regexp in the example says that Unlike has to be at the start of the line.
The first regexp chare is ^ … which means start of line.

Your example wiki wants to start with “dolor” \define myregexp() ^(?!dolor).*$ … which is the 3rd word of "Lorem ipsum dolor… "

So this cannot work.


IMO it would be easier for us, if you show us

  • How is the real structure of your text?
  • How should the desired tiddler look like after the conversion took place.

As Charlie wrote. You are probably using the wrong regeexp.