php wildcard carachter, matching pattern with unknown amount of whitespaces in it in php and with ereg

I want to detect spaces in php with ereg. (it HAS to be ereg NOT preg and NOT eregi)

I want to match a pattern that is following:
1564        XYZYZYZ      5466
ASD1 ZIA              657678767867
6AFA515 XY-Z646-55S-DUZUZ      1ADADS

The amount of dots, numbers, chars+numbers and spaces can highly vary, but template doesn't.

Therefore I am doing:
if( (ereg('([A-Z0-9-]*[A-Z0-9])( *|\n )([A-Z0-9-]*[A-Z0-9])',$val,$alt_to_be_split)) &&  (ereg('( |  |   |    |\n )',$val,$alt_str_to_replace)) )

It works but I get troubles with:
if( (ereg('([A-Z0-9-]*[A-Z0-9])( *|\n )([A-Z0-9-]*[A-Z0-9])',$val,$alt_to_be_split)) &&  (ereg('( *|\n )',$val,$alt_str_to_replace)) )

Difference between 1 and 2 is the use of * as wildcard character to get unlimited amount of whitespaces.

(like in

Any ideas of what it could be?
Who is Participating?
ixtiConnect With a Mentor Commented:
Maybe I just didn't understood something, bt as far as I can understand it should be like this:

if (
    ereg('([A-Z0-9][A-Z0-9-]+)( +|\n *)([A-Z0-9][A-Z0-9-]+)', $val, $alt_to_be_split)
    ereg(' +|\n', $val, $alt_str_to_replace)
ChoobsTechAuthor Commented:
In the same topic: Why doesn't wildcard work for dots either when doing: (\.*)
Do you want to remove whitespaces? and just use the rest splitted?
I saw an error then in the basic regex, an extra *.
try this one:
([A-Z0-9-][A-Z0-9])( *|\n )([A-Z0-9-]*[A-Z0-9])
ChoobsTechAuthor Commented:
The * wildcard takes the char before it an illimited amount of times.

ereg("ap*le", "I saw the apple tree.");
This expression matches the letter a, followed by ZERO OR MORE of the letter p, followed by the letters l and e.

"The + meta-character provides almost the same functionality as the * character, except that the pattern must occur at LEAST ONCE"

In my case, I prefer the + character is suitable as I need at least 1 occurence of whitespace as was pointed ou by ixti.

To sinisazg:
-->([A-Z0-9-]*[A-Z0-9]) works fine, and just means that [A-Z0-9-] can occur ZERO OR MORE times followed by at least 1 time [A-Z0-9].
aces][1 WORD]

The problem was that ( *) looks for 0 or more whitespaces, therefore is buggy when placed alone as a match criteria alone in ereg...

To ixti:
Don't bother to agree with me! I already changed my mind... I was going to reply with vigourous denial to your proposition at your answer before heading to bed (was coding for 17 hrs in a row).
Few hours of sleep later, all I can say is: Why didn't I think of it!!!

Thnx a lot!

All points go to ixti. Feel free to make complaints in here if you feel this has been unequal.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.