Solved

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

Posted on 2014-03-28
1
590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
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'…
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…
Suggested Courses

734 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