Solved

Help with a regex search

Posted on 2009-07-09
3
149 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now