473,387 Members | 1,520 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.

regex , ereg() Problems???

I am having a problem verifying characters in a variable, I am trying
to create a conditional statement based on whether or not the first two
characters of a variable contain "E9". The variable will always be
either a 6 or a 7 digit, alpha-numeric string begining with "E". I have
tried the following ereg() statement and it picks up everything because
it begins with "E". I cannot seem to find any examples for matching
characters in a specific location within a string except for the
begining or the end. I am sure there is a simple solution. Any ideas??

(ereg("^[E9]", $enumber))

Dec 16 '06 #1
2 1380
Rik
dk*******@yahoo.com wrote:
I am having a problem verifying characters in a variable, I am trying
to create a conditional statement based on whether or not the first
two characters of a variable contain "E9". The variable will always be
either a 6 or a 7 digit, alpha-numeric string begining with "E". I
have tried the following ereg() statement and it picks up everything
because it begins with "E". I cannot seem to find any examples for
matching characters in a specific location within a string except for
the begining or the end. I am sure there is a simple solution. Any
ideas??

(ereg("^[E9]", $enumber))
This would mean: Match if the first character if it's in the block between
[], i.e. everything starting with 'E' _or_ '9' will match.
Do not use [] if you're looking for an exact string.

Starting with E9:
preg_match('/^E9/',$number);

Case insensitive (either E or e):
preg_match('/^E9/i',$number);
--
Rik Wasmus
Dec 16 '06 #2

Rik wrote:
dk*******@yahoo.com wrote:
I am having a problem verifying characters in a variable, I am trying
to create a conditional statement based on whether or not the first
two characters of a variable contain "E9". The variable will always be
either a 6 or a 7 digit, alpha-numeric string begining with "E". I
have tried the following ereg() statement and it picks up everything
because it begins with "E". I cannot seem to find any examples for
matching characters in a specific location within a string except for
the begining or the end. I am sure there is a simple solution. Any
ideas??

(ereg("^[E9]", $enumber))

This would mean: Match if the first character if it's in the block between
[], i.e. everything starting with 'E' _or_ '9' will match.
Do not use [] if you're looking for an exact string.

Starting with E9:
preg_match('/^E9/',$number);

Case insensitive (either E or e):
preg_match('/^E9/i',$number);
--
Rik Wasmus
Thanks Rik, I had tried preg_match() but I was trying to use the square
brackets and it was not working. I will give your suggestions a try.
Thanks again for the response...

Dec 16 '06 #3

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

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
3
by: Rafal Zak | last post by:
I have a little problem with ereg (eregi) in PHP - in some cases it behaves differently than I expect and I don`t know if my expectations are strange or there is any "syntax subtlety" I have...
3
by: Dynamo | last post by:
Hi, Thanks to all who replied to original posting.As a direct result of now gaining a better understanding of regular expressions, instead of trying to use other peoples scripts I am now trying to...
7
by: el_roachmeister | last post by:
Is there a good article that explains why php does not support =~ like perl for regex? I am confused by all the different ways one can do regex in php but it would seem supporting =~ would...
3
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
5
by: M Kinnear | last post by:
I want to check a string only contains a-z 0-9 ( ) . and # I've used ereg("^*)$"),$instr) which parses a string correctly until I try and parse a !,",£,$ ... or any of the other...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
2
by: The.Relinator | last post by:
I'm just wondering what the best way is to extract and display a number from a html file. I tried the following piece of code, however it does not work. ereg('\d\.\d', $content, $reg); echo...
3
by: William Gill | last post by:
I am not to sharp on my regular expressions because I haven't used them in quite a while. So I am relearning regex and the PHP regex functions at the same time. Which means when I screw up, I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
0
BarryA
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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.