Storing certain form value in var

Hello

lets say my form value is

&hello john &bye jacob &goodafternoon

How can I store all the values starting with & in a var?

Regards

You can use a regular expression that gets all of the characters that start with an ampersand.


var matches = field.value.match(/(&\\S+)/g);

Hi thank you for your response.

Yes but how do I store that in a var.

for example If the form value is &hello jacob
How do I store &hello in a var?

Regards

The example that I gave stores the values in a var called matches as an array, such as:
[‘&hello’, ‘&bye’, ‘&goodafternoon’]

If you don’t want the ampersand included in the string, you can match /&(\S+)/g instead of /(&\S+)/g

You can use the standard array-index notation to retrieve one of the string values from that array.