Extractregex opening string with formtext


#1

Hi,

Is it possible to specify the opening (or closing) string for a extractregex query using a formtext field?

Here's how I tried it, but it didn't work:

{=extractregex({clipboard}, "{formtext: name=field} ([\w \S]+)")}
{=extractregex({clipboard}, "{formtext: name=field} ([\w \S]+)")}

Or maybe use a defined string? Like this?

{formtext: name=field}
{=extractregex({clipboard}, "{=field} ([\w \S]+)")}

Thanks :slight_smile:


#2

Your second approach is close, however you can't use replacement commands within strings (what is between two quotes). When used in strings, they are treated as normal text.

The proper way to concatenate a string with a form value (or a replacement command) is to use the '&' operator.

For example:

{formtext: name=field; default=val}

A simple example of creating a string using a form value:

{= "The field is: " & field & "."}

And your specific example:

{=extractregex("val a b", field & " ([\w \S]+)")}


#3

Hi Scott,

I'm not sure I understand.

Here's what I'm trying to do

I copy the following into the clipboard:

URL_1: http://testurl_1.com
URL_2: http://testurl_2.com
URL_3: http://testurl_3.com

Next, I want to create a snippet with a field where I can enter either "URL_1: " or "URL_2: " or "URL_3: " and the snippet will give me the respective following text.

I couldn't figure out how to apply the example you gave me to this scenario.


#4

Ah, I figured it out!

Works great! Thanks :slight_smile:

Here's how I did it:

{formmenu: name=Parameter; default=Wide:; News:; Alert:}
This creates the dropdown menu to choose the starting string

{=extractregex({clipboard}, Parameter & " ([\w \S]+)")}
This extracts the text that follows the starting string, till the end of the line

So now if I copy the following into the clipboard:

URL_1: http://testurl_1.com
URL_2: http://testurl_2.com
URL_3: http://testurl_3.com

And then I run the snippet, and input either "URL_1: " or "URL_2: " or "URL_3: ", the snippet will give me the respective following text.

Thanks again!!! :slight_smile: