Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Help with a regex search

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
Slimshaneey
Asked:
Slimshaneey
  • 2
3 Solutions
 
ddrudikCommented:
if you don't have nested comments:
/<!--(?:(?!-->).)*-->/s

Open in new window

0
 
mrjoltcolaCommented:
Something like this. I did not test it.

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


Tag name will be in $2
0
 
ddrudikCommented:
if you want to match your specific tag within a non-nested comment.
/<!--(?:(?!-->).)*<<[MYTAG]>>(?:(?!-->).)*-->/s

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now