code8
code8

Reputation: 103

Get Sub strings from Regex Pattern

I want to get "North" and "6544789" strings separately from "North-6544789-Input.csv" by using Regex pattern. Could you please guide me to get Regex pattern for this string.

Upvotes: 0

Views: 40

Answers (2)

gurvinder372
gurvinder372

Reputation: 68433

Simply try

var items = 'North-6544789-Input.csv'.split("-");

alert( "first item - " + items[0] ); 

alert( "second item - " + items[1] ); 

Upvotes: 1

heemayl
heemayl

Reputation: 42117

Do:

^([^-]+)-([^-]+)-.*

\1 is North, \2 is 6544789.

Demo

Upvotes: 1

Related Questions