Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a number in JS like 2,5 or 2.5
2,5
2.5
I want to use a multi split like
'2.5'.split(/,|./)
but it gives me the wrong output, why ?:
["", "", "", ""]
/,|./ is incorrect regex. It should be in a charatcer class /[,.]/ or be escaped /,|\./
/,|./
/[,.]/
/,|\./
This works: '2.5'.split(/[.,]/)
'2.5'.split(/[.,]/)
Add a comment
Escape the . regex metacharacter
'2.5'.split(/,|\./)
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.