dqd2800
dqd2800
2013-03-08 03:45

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 dongpao5127 8年前

    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
    
    点赞 评论 复制链接分享