Solved

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

Posted on 2014-03-28
1
586 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
key press alert 2 32
iframe - style elements within an iframe 7 36
HTML Anchor Link Problem 3 38
How can I make the first part identical to the second ? 1 26
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

828 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