Domain:
http://hk.yahoo.com
pattern:
"/:\/\/(.*)\.[a-z]{2,4}\//"
code:
ereg("/:\/\/(.*)\.[a-z]{2,4}\//", 'http://hk.yahoo.com', $domain);
target:
hk.yahoo
question:
i can not get it.
2 1318
Heya, Mingkin.
First thing I would do is use preg_match(), as it's faster than ereg(), and it will make your life easier because you can specify your own delimiters: -
preg_match('#://(.+)\\.[a-z]{2,4}#', $str, $matches);
-
print_r($matches);
-
This code looks for '://', then any number of characters followed by '.', then between 2 and 4 characters. The .+ is greedy, so it will match as many characters as possible.
Note that the '\' is escaped in the string above. You should always be careful when escaping characters in a regular expression. For example, if you pass '\/\/' to preg_match(), PHP will 'escape' the '/' characters, so preg_match() still sees '//', which causes a compile error. Instead, you need to do this: '\\/\\/' so that the '/' is still escaped after PHP is done with it.
Hi, pbmods! Thanks you!
Your answer is very detail and useful, i can achieve my target.
Heya, Mingkin.
First thing I would do is use preg_match(), as it's faster than ereg(), and it will make your life easier because you can specify your own delimiters: -
preg_match('#://(.+)\\.[a-z]{2,4}#', $str, $matches);
-
print_r($matches);
-
This code looks for '://', then any number of characters followed by '.', then between 2 and 4 characters. The .+ is greedy, so it will match as many characters as possible.
Note that the '\' is escaped in the string above. You should always be careful when escaping characters in a regular expression. For example, if you pass '\/\/' to preg_match(), PHP will 'escape' the '/' characters, so preg_match() still sees '//', which causes a compile error. Instead, you need to do this: '\\/\\/' so that the '/' is still escaped after PHP is done with it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: NimP |
last post by:
Hi,. I'm trying to detect any links that are contained within an html page
using eregi pattern matching. I was wondering if there are any pattern
matching geniuses out there who could write a...
|
by: Jamie Jackson |
last post by:
Two fairly basic questions:
I need to supply a method with an array of strings, which will
eventually be used to pattern match against another array of strings.
1. Is there a good way to span...
|
by: jason |
last post by:
is there a way to set up an array of bits of generic size, cycle
through all the possible bit patterns, and detect a sub-pattern within
the bit pattern?
for cycling through possible patterns: i...
|
by: hb |
last post by:
Hi,
Would you please tell me how to detect if the client's browser is closed?
I need such event to trigger a database modification.
Thank you
hb
|
by: headware |
last post by:
In his book "Patterns of Enterprise Application Architecture", Martin
Fowler says that using the Table Module pattern to model the domain
logic precludes the use of inheritance and GoF style OO...
|
by: Marcel Hug |
last post by:
Hi NG !
For learning work with patterns I would like to add the MVC-Pattern in my
little application.
On my form (View) I have a TabController with 2 tabs. In each tab I would
like to have a...
|
by: Bubba |
last post by:
Hi,
We have HttpHandlers that can process requests for up to 50 minutes. Those
HttpHandlers are running in an app domain inside the DefaultAppPool. We'd
like the HttpHandlers to be able to...
|
by: dustin |
last post by:
I've been hacking away on this PEP for a while, and there has been some
related discussion on python-dev that went into the PEP:
...
|
by: pbd22 |
last post by:
i have the pattern that checks for bad email:
var pattern=/^()+@()+\.()+()+/;
I want to add a check for a domain name: "mycompany"
such that:
peter@mycompany.com
is a match. and, any...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |