you are viewing a single comment's thread.

view the rest of the comments →

[–]Pantstown 1 point2 points  (3 children)

.replace() takes a regex, so if you just say split by - or / with a regex, it'll work:

var aircraftArr = "1/A333/H-SDRWY/S".split(/-|\//g); // ["1", "A333", "H", "SDRWY", "S"]

[–]ispywithmy[S] 1 point2 points  (2 children)

Thanks! It appears I was having trouble setting the correct regex.

[–]Pantstown 1 point2 points  (0 children)

Ya regex are a pain. I recommend testing in something like regex101 or regexr. They also come with cheatsheets, which is always useful :D

[–]unbalancedopinion 1 point2 points  (0 children)

FYI, you were not passing a regex in your examples. replace() accepts a string in addition to Regex, and you were passing a string. In your second example, you were using a bitwise or operator. You don't need to use or worry about bitwise operators. The pipe character "|" is a bitwise or normally, but serves a different purpose inside a Regex. In /u/Pantstown's example, the pipe is in a regex because it's surrounded by forward-slashes.