Regular expresion question
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Regular expresion question
Look at those lines:
- scarface (teletext pag. 760) - 777
- Total Tv: the beginning - 777
- nobody's land
- national geo - pandas (teletext pag. 528)
how can I do a regular expression on those lines to get only the program name, respectively:
scarface
Total Tv: the beginning
nobody's land
national geo - pandas
?
Any help would be appreciated
- scarface (teletext pag. 760) - 777
- Total Tv: the beginning - 777
- nobody's land
- national geo - pandas (teletext pag. 528)
how can I do a regular expression on those lines to get only the program name, respectively:
scarface
Total Tv: the beginning
nobody's land
national geo - pandas
?
Any help would be appreciated
Re: Regular expresion question
We have a forum just for regular expressions. I've moved this thread there.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Regular expresion question
Assuming that is the full range of possible variations, this might work:klevis miho wrote:Look at those lines:
- scarface (teletext pag. 760) - 777
- Total Tv: the beginning - 777
- nobody's land
- national geo - pandas (teletext pag. 528)
how can I do a regular expression on those lines to get only the program name, respectively:
scarface
Total Tv: the beginning
nobody's land
national geo - pandas
?
Any help would be appreciated
Code: Select all
if(preg_match('/- ([^(:-]+)/', $line, $title)) {
$title = trim($title[1]);
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Regular expresion question
Thnx it worked.
But the last part:
- national geo - pandas (teletext pag. 528)
Didn't display:
national geo - pandas
Any suggestion?
But the last part:
- national geo - pandas (teletext pag. 528)
Didn't display:
national geo - pandas
Any suggestion?
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Regular expresion question
This is the longest text i need to do a regex:
- Mtv commercial - abu & quiz: the knight rider (teletext pag. 528) - 777 - 778
- Mtv commercial - abu & quiz: the knight rider (teletext pag. 528) - 777 - 778
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Regular expresion question
Yeah the text really isn't predictable enough. This is probably the best you'll do and assumes no numbers in the title. Maybe some else can provide a better one:
Code: Select all
if(preg_match('/- ([^(\d]+)/', $line, $title)) {
$title = trim(str_replace('-', '', $title[1]));
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Regular expresion question
Yeah this does this string but it doesnt do this:
MTV 1 K.A.R. - 777
this regular expressions are driving me crazy man
MTV 1 K.A.R. - 777
this regular expressions are driving me crazy man
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Regular expresion question
If the text is not predictable, at least somewhat, then a regex will never give you exactly what you want.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: Regular expresion question
I posted a somewhat predictable text in a challenge here 