Y
Y
Yaroslav Ivanov2021-09-03 15:13:15
JavaScript
Yaroslav Ivanov, 2021-09-03 15:13:15

How to split without extra empty characters?

Hello.

'Value: {string}, value: {string}.'.split(/Value: (.*?), value: (.*?)\./) // ["", "{string}", "{string}", ""]


You can of course do join(" ").trim().split(" "); or .filter(i => i)

But is it possible to do it differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2021-09-03
@space2pacman

'Value: {string}, value: {string}.'.match(/Value: (.*?), value: (.*?)\./).splice(1) // ['{string}', '{string}']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question