Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

edited tags
Link
Maksym Popov
  • 452
  • 1
  • 8
  • 18
Source Link
Maksym Popov
  • 452
  • 1
  • 8
  • 18

How to split string in correct way?

For example, I have this string:

a = "Hello, @USER_ID:1@, how are you?"

I need to turn this string into array of words:

["Hello, ", "@USER_ID:1@", ", how are you?"]

I've tried this piece of code:

a.split(/\@USER_ID:([0-9]+)\@/)

But it returns this:

["Hello, ", "1", ", how are you?"]

What is the proper way to split this string?

lang-js

AltStyle によって変換されたページ (->オリジナル) /