Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-28
1
Medium Priority
?
603 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 83

Accepted Solution

by:
leakim971 earned 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)
Suggested Courses

885 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