473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding multiples instances of an expression

Im trying to expand a search util by uing regular expression to allow
common search criteria such as +-* and phrases "".

My understanding of ereg(string pattern, string string, [array
registers]) is that the array register should collect all instances
that match the pattern.

Heres is an example of the code:

$word4 = "+budgie +ferret dog."; //set phrase

$regexp = "\+[0-9A-Za-z]+"; //assign pattern

if(ereg($regexp, $word4, $reg)){ //test for true result
for($i=0;$i<count($reg);$i++){ //loop through array result
echo "<b>finding multiple instances.:</b> Found string '$reg
[$i]'<br>"; // echo result
}
}else{
echo "<b>finding multiple instances.:</b> $regexp not found"; //
echo if none found
}

This is succesfully finding the first word but id does not find the
second word.

Can anyone point to where im going wrong?

Regards
Tristan
Jul 17 '05 #1
1 2046
Tristan wrote:
This is succesfully finding the first word but id does not find the
second word.

Can anyone point to where im going wrong?


This will work better:

<?php

$word4 = "+budgie +ferret dog."; //set phrase
$regexp = "/(\+[a-z\d]+)+/i"; //assign pattern

if (preg_match_all($regexp, $word4, $matches)) {
foreach($matches[1] as $match) {
print "Word found: $match\n";
}
} else {
print "No match";
}
?>
JW

Jul 17 '05 #2

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

Similar topics

21
1730
by: André | last post by:
Short version of what I am looking for: Given a class "public_class" which is instantiated a few times e.g. a = public_class() b = public_class() c = public_class() I would like to find...
3
1847
by: Tim | last post by:
Hello Everyone I'd like to create a script/program that can locate all servers running DB2, finding out which instances are running/created and what databases are running under them but have...
4
8442
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a...
6
1689
by: Derek Peschel | last post by:
Here are two functions. def invert_dict_to_lists(dict): lists = {} for key in dict: value = dict if not value in lists: lists = else: lists.append(key)
4
1641
by: Dishy78 | last post by:
Hi This is my first time on this site. I have searched help, microsoft, goggle and this forum but cannot find an answer to the following - I'm hoping you can help.... I'm using Access 2003 and...
22
6869
by: Simon Forman | last post by:
Is there a more efficient way to do this? def f(L): '''Return a set of the items that occur more than once in L.''' L = list(L) for item in set(L): L.remove(item) return set(L)
7
4389
by: blaine | last post by:
Hey everyone, For the regular expression gurus... I'm trying to write a string matching algorithm for genomic sequences. I'm pulling out Genes from a large genomic pattern, with certain start...
2
5184
by: Alejandro | last post by:
Hi: I need to find the multiples of a decimal number in a floating point list. For instance, if a have the list , I want the multiples of 0.2: . With integers this problem is easy, just test...
275
12038
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
7229
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,...
0
7129
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...
0
7398
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...
0
7502
tracyyun
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...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
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...

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.