Solved

Help with a regex search

Posted on 2009-07-09
3
152 Views
Last Modified: 2012-05-07
Hi there, I have a requirement to search for the following variations and return an array. The preg_split function is perfect, however its the pattern I need help for. Basically, I will have a long strring with some html comments in there with a specific tag contained, eg:
<!-- <<[MYTAG]>> -->

However, as there may be other comments in there eg:

<!-- <<[MYTAG]>> This has some extra text -->
 or
<!-- Some more text here <<[MYTAG]>> And more here.

However I need the whole comment to be the split point. The important bits are <!-- <<[MYTAG]>> -->

Any one got ideas on how I would go about that?
0
Comment
Question by:Slimshaneey
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 300 total points
ID: 24814147
if you don't have nested comments:
/<!--(?:(?!-->).)*-->/s

Open in new window

0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 200 total points
ID: 24814165
Something like this. I did not test it.

<!--(.*?)<<\[(\w+)\]>>(.*?)-->


Tag name will be in $2
0
 
LVL 27

Assisted Solution

by:ddrudik
ddrudik earned 300 total points
ID: 24814178
if you want to match your specific tag within a non-nested comment.
/<!--(?:(?!-->).)*<<[MYTAG]>>(?:(?!-->).)*-->/s

Open in new window

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
PHP strings vs array errors 13 33
Wordpress French and English Site 6 77
How has this flight information been added to this website? 7 31
Log in through ID 5 18
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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.

829 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