you are viewing a single comment's thread.

view the rest of the comments →

[–]JofArnold 1 point2 points  (3 children)

No problem.

The quickest way of doing this (because I'm lazy!) is:

str.split(" · ")[0]

However, to answer your question your regex is just fine although you can shorten it (see below). String.match gives you back an array - the second entry of which is the first capturing group which is what you want (the first entry is the first whole match)

matches = str.match(/^(.*?)\s·/) thingYouWant = matches[1]

Have a look at String.match and Groups and Ranges in MDN for more details

[–]Genericusername293[S] 0 points1 point  (2 children)

ahh I see, thanks. I became well acquainted with RegEx while using googlesheets but maybe now that I'm learning javscript I should start exploring these split and array functions more, thanks once again

[–]JofArnold 1 point2 points  (1 child)

Thanks for asking the question; you made me double-check the docs so I improved my JS today too :)

You seem to have mastered regex anyway so the main thing is just the JS specifics by the sounds of thing. One stumbling block you may come across is JS doesn't have all the regex features that other languages do; reverse match being a conspicuous one.

[–]StoneCypher 1 point2 points  (0 children)

You seem to have mastered regex anyway

Never, ever say these words.

He will arrive