Link to home
Start Free TrialLog in
Avatar of baska
baska

asked on

ereg function?????

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
Avatar of lokeshv
lokeshv

you just wann to check the specific string (WSEP_23B)

or the pattern..
??


Lk
Avatar of baska

ASKER

I actually want to check the pattern.

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


thanks

Avatar of baska

ASKER

I actually want to check the pattern.

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


thanks

Avatar of baska

ASKER

I actually want to check the pattern.

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


thanks

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
Avatar of baska

ASKER

I wanted to use ereg function only.
ASKER CERTIFIED SOLUTION
Avatar of andreif
andreif
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baska

ASKER

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
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
Avatar of baska

ASKER

hai andreif,

I got it.

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