dqd2800 2013-03-08 03:45
浏览 28
已采纳

preg_match_all无法正常工作。 可能错误的模式。

I'm going to get straight to the point,

Here is my pattern:

/Day [0-9]+:(.*?)Day [0-9]+:/s

Here is my subject:

                Day 1:

House:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Moombahton:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Dubstep:
Song Name: Clap Your Hands
Artist: Walk Home
Facebook Page: https://www.facebook.com/walkhomemusic
Soundcloud Page: https://soundcloud.com/walk-home
Free Download: Yes
Download Link: http://www.mediafire.com/?usi4rtx9q26owbn
Youtube Link: http://www.youtube.com/watch?v=kqfDM1aNjp4
Description: Walk Home really killed it with this song. I especially like this song for the ability to take it across genres. There is a really nice guitar solo in the drop, and I think that is what makes this song. The mixture of analog and digital instruments is phenomenal. The entire song will be a treat to any listener, whether they like Rock, or electronic music. 
Date added to youtube: March 6th, 2013

Glitch Hop:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

DnB:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Other:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:


Day 2:

House:
Song Name: No Expectations
Artist: Hollidayrain
Facebook Page: https://www.facebook.com/HollidayrainMusic
Soundcloud Page: https://soundcloud.com/hollidayrain
Free Download: Yes
Download Link: http://www.mediafire.com/?z2du038l70f7n8s
Youtube Link: http://www.youtube.com/watch?v=VDRl39n1rFQ
Description: Hollidayrain has achieved a new standard in mixing and production with his soon to be hit song No Expectations. The clear and hard hitting drums really emphasize the dirty bass that this amazing electro house song has to offer. It’s clear that Hollidayrain will be on everyone’s radar. Keep a lookout for more great hits from him!
Date added to youtube: March 7, 2013

Moombahton:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:

Dubstep:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:

Glitch Hop:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:

DnB:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:

Other:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:

Day 3:

Here is my results from that pattern:

    array (
  0 => 
  array (
    0 => 'Day 1:

House:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Moombahton:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Dubstep:
Song Name: Clap Your Hands
Artist: Walk Home
Facebook Page: https://www.facebook.com/walkhomemusic
Soundcloud Page: https://soundcloud.com/walk-home
Free Download: Yes
Download Link: http://www.mediafire.com/?usi4rtx9q26owbn
Youtube Link: http://www.youtube.com/watch?v=kqfDM1aNjp4
Description: Walk Home really killed it with this song. I especially like this song for the ability to take it across genres. There is a really nice guitar solo in the drop, and I think that is what makes this song. The mixture of analog and digital instruments is phenomenal. The entire song will be a treat to any listener, whether they like Rock, or electronic music. 
Date added to youtube: March 6th, 2013

Glitch Hop:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

DnB:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Other:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:


Day 2:',
  ),
  1 => 
  array (
    0 => '

House:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Moombahton:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Dubstep:
Song Name: Clap Your Hands
Artist: Walk Home
Facebook Page: https://www.facebook.com/walkhomemusic
Soundcloud Page: https://soundcloud.com/walk-home
Free Download: Yes
Download Link: http://www.mediafire.com/?usi4rtx9q26owbn
Youtube Link: http://www.youtube.com/watch?v=kqfDM1aNjp4
Description: Walk Home really killed it with this song. I especially like this song for the ability to take it across genres. There is a really nice guitar solo in the drop, and I think that is what makes this song. The mixture of analog and digital instruments is phenomenal. The entire song will be a treat to any listener, whether they like Rock, or electronic music. 
Date added to youtube: March 6th, 2013

Glitch Hop:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

DnB:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link:
Youtube Link:
Description:
Date added to youtube:

Other:
Song Name:
Artist:
Facebook Page:
Soundcloud Page:
Free Download:
Download Link: 
Youtube Link:
Description:
Date added to youtube:


',
  ),
)

My intended result was to get day 1 posts, day 2 posts, day n posts all seperated (in the results array). It should be working. The query obviously finds something. But I'm not sure what's going on. Maybe someone brighter than me can guide me in the right direction!

  • 写回答

1条回答 默认 最新

  • dongpao5127 2013-03-08 04:06
    关注

    Backtracking information is discarded when a match is found, so there's no way to tell after the fact that the group had a previous iteration that matched Day [0-9]+: Using Day [0-9]+: as a delimiter is dangerous. What about the last entry? It wouldn't match the criteria. What if the text included 'Day 1:'?

    Looking at your sample it's tough to pick out another delimiter. If you can guarantee a separator between the days, such as 3 or more returns, you could use that as the closing delimiter:

    /Day [0-9]+:(.*?)
    {3,}/s
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?