The application of regular expression to refine the implementation code of Baidu lyrics _ regular expression

Source: Internet
Author: User


The lyrics here are generally LRC format, there is time, if you want to use as text without time, the text inside the time period will become a disturbance barrier.
Here is the LRC lyrics of a song

Copy Code code as follows:

[TI: Heard]
[AR: Liu]
[Al: My Failure and greatness]
[By: Live in the present]
[00:01.22] Liu-heard
[00:03.79] Album name: Heard?
[00:06.73] Lyrics: Gedavey composer: Lin Jianhua
[00:09.74]
[00:10.79]LRC production: Bushu qq:6313827
[00:25.13]
[00:27.08] I hear you've got new faces around
[00:32.04] I hear you're not lonely anymore
[00:35.33] I heard you mentioned me
[00:38.73] I had a good life and I was moved.
[00:45.38] Try to love a few people face love also honest many
[00:52.86] can only be heard to arrange
[00:56.91] About you my right or wrong
[00:60] Two people who used to think alike had changed.
[01:06.18] Only by hearing that they love each other.
[01:10.24] There is no need to prove that the decision was wrong
[01:13.31] think of contact as far as the bottom of my heart greetings
[01:19.56] Nothing is more beautiful than to hear that you still recall
[01:24.8] In fact, I am also grateful when I heard you still believe in love
[01:45.82]
[01:47.83] I heard you often go through the alley
[01:52.76] I hear you're tired of being lonely
[01:56.1] I heard you greet me
[01:59.52] I had a good life and I was moved.
[02:06.04] Try to love a few people face love also honest many
[02:52.11] [02:12.94]
[02:52.67] [02:13.35] can only be heard to arrange
[02:56.63] [02:17.26] About you my right or wrong
[02:59.77] [02:20.32] Two people who used to think alike had changed.
[03:06.11] [02:26.48] Only by hearing that they love each other.
[03:10.07] [02:30.56] There is no need to prove that the decision was wrong
[03:13.1] [02:33.62] think of contact as far as the bottom of my heart greetings
[03:19.31] [02:39.88] Nothing is more beautiful than to hear that you still recall
[03:24.58] [02:45.12] In fact, I am also grateful when I heard you still believe in love
[03:33.66]
[03:36.56] I heard that there are new faces around me
[03:42.53] I heard you blessed me.
[03:52.39]
[03:53.93]LRC production: Bushu qq:6313827

The time period here is very regular, generally with "[" Beginning with "]" end, there is a repetition of the time will appear two period. The first time I thought of the regular expression, I wrote the following procedure with a regular expression
Copy Code code as follows:

<! DOCTYPE html>
<title></title>
<meta charset= "UTF-8"/>
<meta name= "Author" content= ""/>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
<body>
<?php
$contents 2 = "";
$filename = "HTML/TINGSHUO.LRC";
$contents = file_get_contents ($filename);
echo nl2br ($contents);
echo "<br/><br/>";
Preg_match_all ("/\][^\[].*+/", $contents, $array);
$numArray = count ($array [0]);
for ($i = 0; $i < $numArray; $i + +) {
$contents 2.=trim ($array [0][$i], "\]");/remove "]" on the Left
$contents 2.= "<br/>";
}
echo "<br/>echo $contents 2;
echo "<br/>echo "<br/>";
echo "<pre>";
Print_r ($array);
echo "</pre>";
?>
</body>

So, finally saw a gleam of perfect joy--
Copy Code code as follows:

[TI: Heard]
[AR: Liu]
[Al: My Failure and greatness]
[By: Live in the present]
[00:01.22] Liu-heard
[00:03.79] Album name: Heard?
[00:06.73] Lyrics: Gedavey composer: Lin Jianhua
[00:09.74]
[00:10.79]LRC production: Bushu qq:6313827
[00:25.13]
[00:27.08] I hear you've got new faces around
[00:32.04] I hear you're not lonely anymore
[00:35.33] I heard you mentioned me
[00:38.73] I had a good life and I was moved.
[00:45.38] Try to love a few people face love also honest many
[00:52.86] can only be heard to arrange
[00:56.91] About you my right or wrong
[00:60] Two people who used to think alike had changed.
[01:06.18] Only by hearing that they love each other.
[01:10.24] There is no need to prove that the decision was wrong
[01:13.31] think of contact as far as the bottom of my heart greetings
[01:19.56] Nothing is more beautiful than to hear that you still recall
[01:24.8] In fact, I am also grateful when I heard you still believe in love
[01:45.82]
[01:47.83] I heard you often go through the alley
[01:52.76] I hear you're tired of being lonely
[01:56.1] I heard you greet me
[01:59.52] I had a good life and I was moved.
[02:06.04] Try to love a few people face love also honest many
[02:52.11] [02:12.94]
[02:52.67] [02:13.35] can only be heard to arrange
[02:56.63] [02:17.26] About you my right or wrong
[02:59.77] [02:20.32] Two people who used to think alike had changed.
[03:06.11] [02:26.48] Only by hearing that they love each other.
[03:10.07] [02:30.56] There is no need to prove that the decision was wrong
[03:13.1] [02:33.62] think of contact as far as the bottom of my heart greetings
[03:19.31] [02:39.88] Nothing is more beautiful than to hear that you still recall
[03:24.58] [02:45.12] In fact, I am also grateful when I heard you still believe in love
[03:33.66]
[03:36.56] I heard that there are new faces around me
[03:42.53] I heard you blessed me.
[03:52.39]
[03:53.93]LRC production: Bushu qq:6313827
This is the record of the lyrics after processing
Liu-heard
Album Name: Heard?
Lyrics: Gedavey Composer: Lin Jianhua
LRC Production: Bushu qq:6313827
I hear you have new faces around you.
I hear you're not lonely anymore
I heard you mentioned me.
I'm having a good, busy and moving.
Try to love a few people to face love is also honest many
Can only be heard and arranged.
About you, me, right or wrong.
Two of people who used to be alike thought they had changed.
Only by hearing that they love each other.
No need to prove that the decision was wrong.
Think of contact as far as the heart to greet
The most beautiful is to hear you still recall
Actually, I appreciate it when I hear that you still believe in love.
I heard you used to go through my alley.
I hear you're tired of being lonely
I hear you greet me.
I'm having a good, busy and moving.
Try to love a few people to face love is also honest many
Can only be heard and arranged.
About you, me, right or wrong.
Two of people who used to be alike thought they had changed.
Only by hearing that they love each other.
No need to prove that the decision was wrong.
Think of contact as far as the heart to greet
The most beautiful is to hear you still recall
Actually, I appreciate it when I hear that you still believe in love.
I hear there's a new face around me
I heard you blessed me.
LRC Production: Bushu qq:6313827
This is an unhandled lyrics record.
Array
(
[0] => Array
(
[0] =>]
[1] =>]
[2] =>]
[3] =>]
[4] =>] Liu-heard
[5] =>] Album name: Heard?
[6] =>] Lyrics: Gedavey composer: Lin Jianhua
[7] =>]
[8] =>]LRC production: Bushu qq:6313827
[9] =>]
[A] =>] heard you have a new face around
[One] =>] I hear you're not lonely anymore
[of] =>] I heard you mentioned me.
[A] =>] I'm having a good life and I'm still moving.
[] =>] Try to love a few people to face love is also honest many
[A] =>] can only be heard to arrange
[] =>] about you and me right or wrong
[] =>] Two people who used to be alike thought they had changed.
[A] =>] can only be heard by their own love
[s] =>] No need to prove that the decision was wrong
[] =>] think of contact as far as the bottom of my heart greetings
[=>] The most beautiful thing is to hear you still recall
[to] =>] Actually, I appreciate it when I hear that you still believe in love.
[A] =>]
[=>] I heard you used to go through the alley.
[O] =>] I hear you're tired of being lonely
[] =>] I hear you greet me
[M] =>] I'm having a good life, busy and moving.
[] =>] Try to love a few people to face love is also honest many
[=>]
[] =>] can only be heard to arrange
[to] =>] about you my right or wrong
[A] =>] Two people who were similar once thought they had changed.
[A] =>] can only be heard by their own love
[=>] No need to prove that the decision was wrong
[km] =>] think of contact as far as the bottom of my heart greetings
[=>] The most beautiful thing is to hear you still recall
[Panax] =>] Actually, I appreciate it when I hear that you still believe in love.
[=>]
[M] =>] I hear there's a new face around me
[+] =>] I heard you blessed me.
[A] =>]
[=>]]LRC production: Bushu qq:6313827
)
)

Done, regular expressions to deal with this kind of problem really good, if there is a better proposal for this question, welcome message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.