Is there a way to conditionally run a widget?

Hello there - I have a problem with chat gpt being inconsistent. I tell it 3 ways that I need json to start with an open curly brace and end with a closed one, and it returns { “json”: "{ 75% of the time.

I created regex replacements to fix its json, just as it decided to heed my command for proper braces.

I was wondering if there’s a way to conditionally run the replacement only if the first characters include “json” in quotes or something better.

Right now I’m removing { “json”: " from the start of the string and }" from just before the end.

I don’t want to do that if I get back good json.

Can I conditionalize the regex replace?

thank you!

Got it - in case someone needs it, replace accepts “if”:

{{if(indexOf(10.stupid json; “json”; “>-1 “) | indexOf(10.stupid json; “result:”; “>-1”); )}}{{“result"”: "”{\n” | “"“json"”: "”{\n"}}

if {
“result”: "{\n or
“json”: " "{\n
is in the input string
}
{ then replace with an open curly brace}
else { a nonsense word to make your day brighter.}

If the input is this, it gets replaced with an open curly brace:
“result”: "{\n "primary_main_section": {\n "title": "## How Can You Simplify Heavy Duty Mobility Scooter Maintenance?",\n "content": "When it comes to your heavy-duty mobility scoot

But if it’s this, then the text remains the same:
“SearchFailsresult”: "{\n "primary_main_section": {\n "title": "## How Can You Simplify Heavy Duty Mobility Scooter Maintenance?",\n "content": "When it comes to your heavy-duty mobility scoot

But the point is, you can use “if” in a regex.

2 Likes