Solved

JavaScript/REGEX: Get content from between two points in string

Posted on 2014-03-28
1
584 Views
Last Modified: 2014-03-28
Using JavaScript and Regular Expressions, how can I get the content from a string between  
{[English]}
and
{[/English]}
?

This does not work, probably because of escaping related issues:
var data = '{[Spanish]}Hola{[/Spanish]}{[English]}Hello{[/English]}{[Italian]}Ciao{[/Italian]}';
alert(  data.match('{[English]}(.*){[/English]}')[1] );

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39962092
You need to use a regex in match not a string
I mean : new RegExp or /your regex here/

Test page : http://jsfiddle.net/c8SUZ/

var data = '{[Spanish]}Hola{[/Spanish]}{[English]}Hello{[/English]}{[Italian]}Ciao{[/Italian]}';
alert(  data.match(/{\[English\]}(.*){\[\/English\]}/)[1] );

Open in new window


You need also to escape : [] and /
The escaping char is : \
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question