473,769 Members | 5,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Eregi pattern matching - bit of a challenge I thinks

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 pattern that merges all the
different manners in which a link could be wriiten,

Current patterns I can think of include:

<a href=x.com> no spaces betwen href, equals and url, no quotation marks
around url
<a href =x.com> space between href and equals, no space between equals and
url, no quotation marks round url
<a href= x.com> no space between href and equals, space between equals and
url, no quotation marks around url
<a href = x.com> space between href and equals, space between equals and
url, no quotation marks round url
<a href='x.com'> no spaces betwen href, equals and url, single quotation
marks around url
<a href ='x.com'> space between href and equals, no space between equals and
url, single quotation marks round url
<a href= 'x.com'> no space between href and equals, space between equals and
url, single quotation marks around url
<a href = 'x.com'> space between href and equals, space between equals and
url, single quotation marks round url

<a href="x.com"> no spaces betwen href, equals and url, double quotation
marks around url
<a href ="x.com"> space between href and equals, no space between equals and
url, double quotation marks round url
<a href= "x.com"> no space between href and equals, space between equals and
url, double quotation marks around url
<a href = "x.com"> space between href and equals, space between equals and
url, double quotation marks round url

<a href='x.com"> no spaces betwen href, equals and url, mismatched quotation
marks around url - single open, double to close
<a href ='x.com"> space between href and equals, no space between equals and
url, mismatched quotation marks around url - single open, double to close
<a href= 'x.com"> no space between href and equals, space between equals and
url,mismatched quotation marks around url - single open, double to close
<a href = 'x.com"> space between href and equals, space between equals and
url, mismatched quotation marks around url - single open, double to close

<a href="x.com'> no spaces betwen href, equals and url, mismatched quotation
marks around url - double open, single to close
<a href ="x.com'> space between href and equals, no space between equals and
url, mismatched quotation marks around url - double open, single to close
<a href= "x.com'> no space between href and equals, space between equals and
url,mismatched quotation marks around url - double open, single to close
<a href = "x.com'> space between href and equals, space between equals and
url,mismatched quotation marks around url - double open, single to close
I guess whats needed is something more advanced than

eregi("href=\"/(.*)\">",string ,$arryaholding_ results))

I'd appreciate any help you could give,

Thanks
NimP


Jul 17 '05 #1
1 3800
"NimP" <st*@sturobbie. co.uk> wrote:
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 pattern that
merges all the different manners in which a link could be wriiten,

I'm sure there is an easier solution out there somewhere, but by going
through your examples I came up with that (wouldn't validate an URL
though):

preg_match("/<a(\s)+href(\s) *=(\s)*(['\"])*([a-z0-9_\-\.])+(['\"])*>/i",
$string, $matches);

echo htmlentities($m atches[0]);

JOn
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2762
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google page for a text match, and return true or false. eregi returns false whatever the case, similar_text returns true whatever the case. Can someone sort me out - oops, HELP me out ?
2
4034
by: Frank | last post by:
I'm having trouble detecting whitespaces in strings. Set up this test: echo "<br>example 1:".intval(eregi("^\s","teststring")); echo "<br>example 2:".intval(eregi("^\s","test string")); Both resulting in 0 (zero) also tried and without result
25
6509
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate $email = $_POST // Use John Coggeshalls script to validate the email address if(!eregi("^+(\.+)*@+(\.+)*(\.{2,3})$", $email) { echo "The e-mail was not valid";
3
1524
by: LRW | last post by:
I'm trying to make sure a search text field has only numbers, letters, or spaces. I started with this: $pattern = "^()"; if (eregi($pattern, $search_txt)) { And that works so long as the 1st character isn't a number or letter, otherwise it allows the whole string. I did some newsgroup looking, and everything I've found has been for very
8
6981
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just use pattern matching to determine if the proper amount of numeric characters has been met. Here is the function I've already done. Any help you can give in a pattern matching solution would be much appreciated and very educational.
176
8182
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? Thank you, -- greetz tom
9
3217
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images files from gif # format to png format. Now you need to change the # html code to use the .png files. So, essentially
1
2738
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001 94100 If I run a pattern matching search for the string "940", then I should get the top two rows of data back. If I run a pattern matching search for the string "94", then I should get all the three rows of data back.
5
5758
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I have a list, as below: sentence = "the color is $red" patterns = pos = sentence.find($)
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.