?
Solved

issue with regular expressions

Posted on 2006-07-15
2
Medium Priority
?
191 Views
Last Modified: 2006-11-18
I am parsing some text that looks like this:


the girl's name is [[child_name]], and her brother's name is [[brother_name]]. They went to the park.

I'm using this:
      $text = preg_replace("/\[\[(.*)\]\]/","<input type=\"text\" name=\"$1\" value=\"$1\" onfocus=\"this.value='';\">",$text);

So the desired effect is:
The girl's name is <input type="text" name=\"child_name" value="child_name">.  

But what I'm getting is
The girls's name is <input type="text" name="child_name]], and her brother's name is [[brother_name" value="child_name]], and her brother's name is [[brother_name">

Any ideas why this is happening?

Thanks for your help.
0
Comment
Question by:bandyell
[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
2 Comments
 
LVL 9

Accepted Solution

by:
tolgaong earned 1000 total points
ID: 17115744
$text= preg_replace('/\\[\\[(.*?)\\]\\]/', "<input type=\\\"text\\\" name=\\\"$1\\\" value=\\\"$1\\\" onfocus=\\\"this.value='';\\\">", $text);
0
 

Author Comment

by:bandyell
ID: 17115820
wonderful, thanks.  Regular expressions has always been my weak point.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 how to dynamically set the form action using jQuery.
Suggested Courses

762 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