473,219 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

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 2031
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
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
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
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
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
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
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
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
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
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'
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.