Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with a regex search

Posted on 2009-07-09
3
Medium Priority
?
156 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
[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
3 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 1200 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 800 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 1200 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

Technology Partners: 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

This article discusses four methods for overlaying images in a container on a web page
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

660 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