Need help writing ereg...

  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 11, 2004
  • Posts: 456
  • Loc: Dhaka, Bangladesh
  • Status: Offline

Post May 20th, 2004, 3:35 am

Well, I have been trying and I don't know what I am missing. Here is what I want to do:

Replace this: [anything="regular expression goes here"]
With: empty string or " " .

I want to use the ereg function for that. I tried many variations to match the pattern without success. One example:

PHP Code: [ Select ]
$text = ereg_replace("^[\[]+[.]+[\]]+$", "", $text);


For someone experienced it'll probably take a minute to get the right pattern. Where am I doing wrong?[/code]
Web development company : quantumcloud

Web design company : web.com.bd
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 20th, 2004, 3:35 am

  • Carnix
  • Guru
  • Guru
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 1099
  • Status: Offline

Post May 20th, 2004, 3:09 pm

try:
Code: [ Select ]
/^\[[^\]*]$/


This pattern matches your string, although without more context, I don't know if this will actually work for you...

*EDIT: I threw in the / delimiters... they are not technically part of the pattern of course.

.c
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 11, 2004
  • Posts: 456
  • Loc: Dhaka, Bangladesh
  • Status: Offline

Post May 20th, 2004, 5:48 pm

Well, it is not working. There is not much more details to share here. Retrieve a string like this from the database:

[abcd="efghijks"]bnbnsb nsb snbsn

And strip it off of anything inside the brackets, including the brackets. When you test you can just use this example to get rid of [...] and output the rest of the string.

Could you please check out with your pattern, if it works for it? I did, and it is not working for me. :(
Web development company : quantumcloud

Web design company : web.com.bd
  • this213
  • Guru
  • Guru
  • User avatar
  • Joined: Mar 01, 2004
  • Posts: 1242
  • Loc: ./
  • Status: Offline

Post May 21st, 2004, 7:45 am

$text =~ s/\[.*\=\".*\"\]//;

I think
http://www.disabo.com
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 1099
  • Status: Offline

Post May 21st, 2004, 12:05 pm

Ok, on second look, my previous attempt wasn't quite right.

This should do it, I think. Achored at the start, fine an open bracket. Then between the open bracket, find one or more characters that isn't a close bracket until you get to a close bracket, then save anything that comes after it and replace the whole string with that. This is Perl, I'm blanking on the PHP translation off the top of my head.

Code: [ Select ]
$cmd = s/^\[[^\]+]\](.*)/$1/ig;


Give that a try and see. Sorry I couldn't be more help with PHP... I keep all my PHP resources at my home office where I do freelance work, since my work is an ASP shop. Helps keep me honest and ethical =]

.c
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 11, 2004
  • Posts: 456
  • Loc: Dhaka, Bangladesh
  • Status: Offline

Post May 22nd, 2004, 1:50 am

Thank you guys. We finally did it!

Though none of the ones suggested worked exactly. I kept tweaking both of yours and one variation of this213's worked!

The working pattern is like this:
PHP Code: [ Select ]
$text = ereg_replace("\[.*\=\".*\"\]", "replacement", $text);


:)
Web development company : quantumcloud

Web design company : web.com.bd

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 263 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.