| | |
What is the php regular expression to get everything before a certain character?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
What is the php regular expression to get everything before a certain character?
0
#1 Feb 21st, 2009
For instance, I have the following string:
table:column
I need to get "table" as the result of the php regular expression.
So, I need everything before the ":" symbol
After that regular expression is performed, I would also like to get everything after the ":" symbol, or "column" as well.
table:column
I need to get "table" as the result of the php regular expression.
So, I need everything before the ":" symbol
After that regular expression is performed, I would also like to get everything after the ":" symbol, or "column" as well.
Re: What is the php regular expression to get everything before a certain character?
0
#2 Feb 21st, 2009
^(.+?):(.+?)$ That's pretty much it. That's a pretty simple regex, you might want to study them for yourself http://www.regular-expressions.info/, it's a pretty decent resource. GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Feb 2009
Posts: 10
Reputation:
Solved Threads: 2
Re: What is the php regular expression to get everything before a certain character?
0
#3 Feb 21st, 2009
in this case I would use split.
php Syntax (Toggle Plain Text)
$parts = split(":", "table:column"); $parts[0] //table $parts[1] //column
Re: What is the php regular expression to get everything before a certain character?
0
#4 Feb 21st, 2009
•
•
•
•
in this case I would use split.
php Syntax (Toggle Plain Text)
$parts = split(":", "table:column"); $parts[0] //table $parts[1] //column
Re: What is the php regular expression to get everything before a certain character?
0
#5 Feb 21st, 2009
Split and explode are the same thing, they are just two different names.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Re: What is the php regular expression to get everything before a certain character?
1
#6 Feb 21st, 2009
Re: What is the php regular expression to get everything before a certain character?
0
#7 Feb 21st, 2009
That and explode is supposed to execute faster due to the lack of regex, although for what the OP wants, I doubt it will make much difference which is used.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Re: What is the php regular expression to get everything before a certain character?
0
#8 Feb 21st, 2009
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
Join Date: Apr 2008
Posts: 20
Reputation:
Solved Threads: 2
Re: What is the php regular expression to get everything before a certain character?
0
#9 Feb 21st, 2009
•
•
•
•
If explode uses a string and split uses regex then what does preg_split use? What is the difference between split and preg_split? Just curious.
"documentation says that preg_split() is faster than split()"
http://blog.brianhartsock.com/2007/0...lode-vs-split/
"preg_split(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to split(). If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine."
- http://uk3.php.net/split
Some speed stats: http://forums.codewalkers.com/php-co...ode-71423.html
So in answer to your question, preg_split uses regex like split. However, I don't know what the exact difference is.
![]() |
Similar Threads
- perl arrays (Perl)
- regular expressions in php (PHP)
- regular expression (PHP)
- Open In New Window Php (PHP)
- preg_replace (PHP)
- help with pregmatch (PHP)
- Need help making simple random images (PHP)
Other Threads in the PHP Forum
- Previous Thread: MySQL Trouble
- Next Thread: Trouble with Ajax registration form...!
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube






