1

i kind of have a problem to filter out my string, cant figure out a simple way todo that,

i would love to split my string into and array where the words surrounded with {{WORD}}, get into one array piece and the string without into another,

lets say i have this string here:

{{participant_name}} picked {{picked_skills}} skills this round!

would love to split it into an array as following:

array[0]: {{participant_name}}
array[1]: picked
array[2]: {{picked_skills}}
array[3]:  skills this round!

would appreciate all help i can get

2
  • What's the expected output if this was the input string: {{a}} b c {{d}} e f g {{h}} {{i}} {{j}} k l m n o {{p}}? Commented Jul 31, 2020 at 1:34
  • so the expected output would be an array as following: array[0]: {{a}}, array[1]: b , array[2]: c, array[3]: {{d}} and so on .. Commented Jul 31, 2020 at 1:36

1 Answer 1

2
const regexQuery = /{{(.+)}} (.+) {{(.+)}} (.+)/g
const arr = regexQuery.exec('{{participant_name}} picked {{picked_skills}} skills this round!')
arr.shift()
console.log(arr)
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't work if the string changes to {{participant_name}} picked up {{picked_skills}} skills this round! According to OP's response to my question earlier, the result should include the word "up" in a separate array element. But doing that makes the regex not match.
@Jon I was assuming that the 2nd variable is always a single word, but here you go, updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.