Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help with a regular expression

Need help with a regular expression

Need help with a regular expression

I have a string that I read in from a text file in the format of:


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?


RE: Need help with a regular expression

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!|http://www.blah.com?balh=blah&;blah2=blah%20blah

and parsing it using ereg so that the strings in the array turn out to be

blah, blah, blah!



thanks in advance

RE: Need help with a regular expression

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!|http://www.blah.com?balh=blah&;;blah2=blah%20blah

then you could use something like this:

   $a = "blah, blah, blah!|http://www.blah.com?balh=blah&;;blah2=blah%20blah";

  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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close