Using RegEx Evaluator in a Button function

Greetings Gurus, I want to use a Regex Evaluator in a standard function but I'm not clear exactly on how to do it.

Let's say I have a simple function Go {clip}.
I'd like to do a regex replace on the {clip} as it's run.
How do I accomplish this?
Is it something like this, I want to test if the string has quotes?

@if:RegEx({clip}, "[^"]*")
@confirm Match
@if:else
@confirm No match

The statement can have this form...

Go {=RegEx(Clip(), "", "")=}

... or this:

=return "Go " + RegEx(Clip(), "", "")
1 Like

Greetings LXP, now is the syntax you provided for a Standard Opus function or a script?
I thought clipboard contents were accessed via {clip} not Clip().
Please elaborate a bit. Thanks

In the Evaluator kingdom, all the curly-bracket thingies have their non-curly-bracket counterparts. For {clip} it is Clip().

So, yes, the syntax is for the Standard Opus function.

Ok, I'm close but still having issues.

I'm trying to use the Regex to ensure there are no embedded quotes in the string followed by placing quotes (catch-all).
This function basically should go to the folder/file if the path has quotes or not.

Having this string on the clipboard and running the function yields no result.
"D:\APPZ\go clip.txt"
What am I doing wrong here? The Regex should be stripping embedded quotes. And the quotes outside the brackets are there?!

Go "{=RegEx(Clip(), "\"", "")=}"

I've added code blocks to your posts to fix some of the characters being misinterpreted so they weren't displayed properly on the forum.

See Formatting tips specific to the Opus forum (also linked above the editor when writing a post/reply) for details.

1 Like

Use Replace() instead of RegEx(), and escape quotes using "" rather than \".

1 Like

This will strip off all the double quotes and then Go to the quoted result it exists (otherwise, you might get invalid paths).

@evalalways: c = Replace(Clip(), """", "");
= return Exists(c) ? ("Go """ + c + """") : "";

Hope I understood your request correctly!

Thanks Errante, that did the trick. thanks LXP for pointing me in the right direction. Now after Go there are 3 quotes """ and before the closing parenthesis there are 4 quotes """" please explain that.
I think I got it, it's 3 quotes to escape a quote. The fourth quote at the end is just the final quote for enclosing the entire function.

Also what's the link to the documentation where these examples are.

Thanks everyone, I understand it a bit but I need to check out some more examples and read the documentation.

This function allows me to quickly navigate to paths that are quoted or unquoted.

= return "Go """ + Replace(Clip(), """", "") + """ openindest";

That's an excellent plan! You can test your learning progress by finding out why this

is not the correct explanation :slight_smile: