Click here to Skip to main content
15,885,900 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create a JavaScript that can pick the word between two characters
for example:
Let's say I have this:

JavaScript
var myString = "Get me 0between0 results";
var results; //to store results which should be "between"


regular expression to get result as "between" without those zeros.

Thanks In Advance.
Posted

Use substring.
JavaScript
var myString = "Get me 0between0 results";

var start_pos = myString.indexOf('0') + 1;
var end_pos = myString.indexOf('0',start_pos);
var text_to_get = myString.substring(start_pos,end_pos);

alert(text_to_get);

DEMO - [Demo] Find String between Character[^]
 
Share this answer
 
Comments
Bradley Bradman 12-Oct-14 7:00am    
Thank you very mach it really you really helped and am grateful that you responded so fast.
Most welcome. Glad it helped. :)

Thanks,
Tadit
You can try with the below statement:
var String=str.substring(str.lastIndexOf(":")+1,str.lastIndexOf(";"));

also if you need in javascript: please check the below fiddle:
Fiddle[^]
 
Share this answer
 
v2
Comments
Suraj, see my solution. You are not exactly correct.
[no name] 11-Oct-14 12:23pm    
Got you Tadit..thanks for this.I checked the fiddle but anticipated the code block to b correct..:)
[no name] 11-Oct-14 12:24pm    
I guess I considered a singl string ...
Bradley Bradman 12-Oct-14 7:02am    
Thank you very much.... And thanks for redirecting to fiddle for confirmation.
It really helped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900