Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a regular expression

Status
Not open for further replies.

ksoong

Programmer
Oct 3, 2000
57
CA
I have a string that I read in from a text file in the format of:

string1|string2|string3|string4|...

where '|' is the delimiting character. i need to come up with a regular expression that will allow me to parse these strings with ereg to put into an array.

so far I have something like

ereg("(^.|.*)|(^.|.*)|(^.|.*)", $BUFFER, $temparray);

But this must be wrong can someone help me?

thanks.
 
I failed to mention in my post that the strings could contain any sequence of characters including &*^%$#@!~` etc. etc.

I can't figure out the correct regular expression which takes

blah, blah, blah!|
and parsing it using ereg so that the strings in the array turn out to be

blah, blah, blah!

and


thanks in advance
 
I'm not that familiar with "ereg", but if all you want to do is split up a line into tokens based on a delimiter, then look at "split", "explode", "strtok" - here's how you could use split:

$a = "xxx|yyy|zzz";
$token_array = split("|", $a);

And if you want to get everything before http in

blah, blah, blah!|
then you could use something like this:

$a = "blah, blah, blah!|
list($before_http, $rest_of_line) = split("http", $a);

but of course $rest_of_line would *NOT* contain "http" since we used that as the delimiter.

Not exactly sure what you're looking for, but maybe this will point you in the right direction.
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top