Solved

ereg function?????

Posted on 2002-04-09
10
212 Views
Last Modified: 2008-03-06
hai all,

How to check my string
WSEP_23B
using ereg function
I use this below code cannot achieve my target.
ereg("^([A-Z]{4})."_".([1-9]{1,2}[A_Z]$",trim($value[2]))


can anyone help me
bye
0
Comment
Question by:baska
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 6927627
you just wann to check the specific string (WSEP_23B)

or the pattern..
??


Lk
0
 

Author Comment

by:baska
ID: 6927633
I actually want to check the pattern.

but I don't mind knowing the coding to check for the specifc string also.


thanks

0
 

Author Comment

by:baska
ID: 6927635
I actually want to check the pattern.

but I don't mind knowing the coding to check for the specifc string also.


thanks

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:baska
ID: 6927637
I actually want to check the pattern.

but I don't mind knowing the coding to check for the specifc string also.


thanks

0
 
LVL 4

Expert Comment

by:lokeshv
ID: 6927653
for specific string .search use string funtions.

like

str_replace()
substr_count();



for more check this ...

http://www.php.net/manual/en/ref.strings.php
0
 

Author Comment

by:baska
ID: 6927673
I wanted to use ereg function only.
0
 
LVL 6

Accepted Solution

by:
andreif earned 25 total points
ID: 6927678
Hi,

you have some mistakes in your expression

"^([A-Z]{4})."_".([1-9]{1,2}[A_Z]$"

should read as

"^([A-Z]{4})_([1-9]{1,2}[A-Z])$"

problem 1: expression ."_". in the centre is confusing, because it splits string into two "^([A-Z]{4})." and ".([1-9]{1,2}[A_Z]$" and _ between those string must cause an error

problem 2: A_Z should read as A-Z - just a mistype
problem 3: closing brace ) was missed

That's all!
0
 

Author Comment

by:baska
ID: 6927700
hai andreif,
I actually check thru if condition like

if (strlen(trim($value[2])) == 8 && ereg("^([A-Z]{4})_([1-9]{1,2}[A-Z])$",trim($value[2])));

 echo "<td>".trim($value[2])."</td>";
else
 //display $value in red color in browser.

as u told I change the coding but still I can see the value in red color ie it takes the else condition only.

can u advice where I went wrong.

Thank u
baska
0
 
LVL 6

Expert Comment

by:andreif
ID: 6927709
Hi,

it seems correct, at least it works at me.

Can you give an examples of $value[2] values?

Note:
1. expression is CAse SenSitive now :)
2. you don't have to check length, because regular expression has require rather strict string format, it allows strings like

ABCD_1E or ABCD_12E, so if you need only strings with 2 digits (length=8) you should replace [1-9]{1,2} with [1-9]{2} and don't worry about length
0
 

Author Comment

by:baska
ID: 6927764
hai andreif,

I got it.

I just did a simple mistake.
I added the coding as u gave now works well
Thank u
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question