473,387 Members | 3,750 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,387 software developers and data experts.

Regular Expressions help!

Probably, it is simple but honestly I am not able to solve this
problem.

I am trying to use eregi_replace() function to substitute some strings
in my input.

I would like to substitute the "ac" substring when it is a single word
(i.e. "ac" or "ac " but not "ace" or "mace").

I tried something like:

ereg_replace("ac[^[:alpha:]]*","subst...",$inputstring));

But it fails...

I read the regex help and online documentation but I was not able to
figure how to obtain it...

Please help!

Thanks,
Massimo
--
http://incuso.altervista.org
Jul 17 '05 #1
8 1686
On 13 Nov 2004 06:50:06 -0800, nu*********@gmail.com (Massimo at HOME) wrote:
Probably, it is simple but honestly I am not able to solve this
problem.

I am trying to use eregi_replace() function to substitute some strings
in my input.

I would like to substitute the "ac" substring when it is a single word
(i.e. "ac" or "ac " but not "ace" or "mace").

I tried something like:

ereg_replace("ac[^[:alpha:]]*","subst...",$inputstring));

But it fails...

I read the regex help and online documentation but I was not able to
figure how to obtain it...


Don't use the ereg* functions, use the preg* functions. They're typically
faster, and have a more powerful expression language (Perl-compatible).

http://uk.php.net/manual/en/ref.pcre.php
http://uk.php.net/manual/en/referenc...ern.syntax.php
http://uk.php.net/preg_replace

Have a look at \b - zero-width word boundary assertion.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Massimo at HOME <nu*********@gmail.com> wrote:
I would like to substitute the "ac" substring when it is a single word
(i.e. "ac" or "ac " but not "ace" or "mace").

I tried something like:

ereg_replace("ac[^[:alpha:]]*","subst...",$inputstring));

But it fails...


Why use ereg_replace?

$ cat /tmp/foo.php
<?php

$str='foo ac mace bar';

echo "before: $str\n";
$str=preg_replace('/\bac\b/','xx',$str);
echo "after : $str\n";
?>
$ php4 /tmp/foo.php
before: foo ac mace bar
after : foo xx mace bar
$

Jul 17 '05 #3
On 13 Nov 2004 15:15:02 GMT, Daniel Tryba <sp**@tryba.invalid> wrote:
Massimo at HOME <nu*********@gmail.com> wrote:
I would like to substitute the "ac" substring when it is a single word
(i.e. "ac" or "ac " but not "ace" or "mace").

I tried something like:

ereg_replace("ac[^[:alpha:]]*","subst...",$inputstring));

But it fails...
Why use ereg_replace?


Why ask why? He was asking for help. Why demean his question?


$ cat /tmp/foo.php
<?php

$str='foo ac mace bar';

echo "before: $str\n";
$str=preg_replace('/\bac\b/','xx',$str);
echo "after : $str\n";
?>
$ php4 /tmp/foo.php
before: foo ac mace bar
after : foo xx mace bar
$


Neat answer, but I liked the first and yet similar response. The
poster wasn't a jerk and gave several URLs and a tip about \b so the
person asking the question could learn for himself.
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #4
Gary L. Burnore <gb******@databasix.com> wrote:
Neat answer, but I liked the first and yet similar response. The
poster wasn't a jerk and gave several URLs and a tip about \b so the
person asking the question could learn for himself.


Thank you for calling me a jerk.

If you have nothing nice to say blabla...

Jul 17 '05 #5
On 13 Nov 2004 15:24:32 GMT, Daniel Tryba <sp**@tryba.invalid> wrote:
Gary L. Burnore <gb******@databasix.com> wrote:
Neat answer, but I liked the first and yet similar response. The
poster wasn't a jerk and gave several URLs and a tip about \b so the
person asking the question could learn for himself.


Thank you for calling me a jerk.


I said he wasn't a jerk. I didn't say you were. But then, if the shoe
fits. I do note that you can't argue my point.
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #6
Gary L. Burnore <gb******@databasix.com> wrote:
Neat answer, but I liked the first and yet similar response. The
poster wasn't a jerk and gave several URLs and a tip about \b so the
person asking the question could learn for himself.


Thank you for calling me a jerk.


I said he wasn't a jerk. I didn't say you were. But then, if the shoe
fits. I do note that you can't argue my point.


If I only could find out that your point was...

Oh wait, I don't actually care.

Jul 17 '05 #7
Gary L. Burnore wrote:
On 13 Nov 2004 15:15:02 GMT, Daniel Tryba <sp**@tryba.invalid> wrote:

Why use ereg_replace?


Why ask why?


Why not?

--
Jock
Jul 17 '05 #8
Gary L. Burnore <gb******@databasix.com> wrote in message news:<cn**********@blackhelicopter.databasix.com>. ..
Neat answer, but I liked the first and yet similar response. The
poster wasn't a jerk and gave several URLs and a tip about \b so the
person asking the question could learn for himself.


I already learnead about \b and read the docs, but I was missing the /

Thanks,
Massimo
--
http://incuso.altervista.org
Jul 17 '05 #9

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

Similar topics

11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
4
by: GenoJoe | last post by:
If you are not new to VB.NET but are new to regular expressions, you need to get a free copy of "Pragmatic Guide to Regular Expressions for VB.NET Programmers". I wrote this guide because all of the...
2
by: cleo | last post by:
I'm experimenting with Regular Expressions and Windows Forms. Frequently I want a value to be either a valid pattern or empty. For example a Zip code must be 5 digits or may be empty. I know that...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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...

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.