user5405873 user5405873 - 20 days ago 5
Javascript Question

how to pick middle text between 2 changing string

how to get center text

in yeshvanthpur , bangalore
, i,e
yeshvanthpur
from

the string.

in[constant always] yeshvanthpur[changes every time] , bangalore [changes every time]


in above pattern
in
will remain constant every time. where as
yeshvanthpur
and
bangalore
will changes every time.

question: i want to get
yeshvanthpur


test cases:

in yehlanka , bangalore // expected output : yehlanka

in bandra , mumbai // expected output : bandra

in mathikere , bangalore // expected output : mathikere


please bear with me as i don't know
regex


the only code i have

var str = 'in yehlanka , bangalore';


please help me thanks in advance

Answer

try this if in and , are gonna be constant

var str = 'in yehlanka , bangalore';


str.split(',')[0].split('in')[1].trim() //output yehlanka