Re: [PHP] Re: Help with Regular Expressions
From: <[EMAIL PROTECTED]> > Hi all, > > I am working on a small php script which should do the > following. I want all the links in the page to be > preceded by first character and first two characters > of the link.Please look into the example below for > more > clarification. > > eg. > link here to be > replaced as > link here > > I guess, this is possible by using regular expressions > but I am not able to crack the right expression. > Hi, This is not very simple. The URI which in your example is /code.html can be anything, including something like m.html. In that case which would be the first 2 letters? Or, the URI can be something like m-like.html. In this case the first 2 letters will be "m-" or "ml"? A good regular expression should work in all situations so it is important to know what is the desired result, and not to asume that there won't be any links like "/.html" or something worse. Teddy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Help with Regular Expressions
Hi all, I am working on a small php script which should do the following. I want all the links in the page to be preceded by first character and first two characters of the link.Please look into the example below for more clarification. eg. link here to be replaced as link here I guess, this is possible by using regular expressions but I am not able to crack the right expression. Any help would be highly appreciated in this regards. Cheers, Killu Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Help with regular expressions
Hi Daniel, "José daniel ramos wey" ... > Hi! I´m new to regular expressions, and it seems to be an art to make it > work as expected. > > I´m trying to remove all "single-line" comments from an string - that´s > everything after "//" to the end of a line. I expected that this would do > the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work. > > Any tips? First off, IMO, you're better off using pcre regex functions than the posix ones: http://www.php.net/preg_replace Your regex is basically saying this: //[[:alnum:]]*\n Match anywhere in the string (you have no anchor as to where the // should start), consume anything that is alphanumeric (0 through 9, a through z), as many times as they occur, followed by a new line. Thus, your regex would consume stuff like this: //sdfdfffsdfsdfsdd12345678900987sdfsdbfs but not // sdfdfffsdfsdfsdd12345678900987sdfsdbfs or // this is a comment. as for my example, I'm using exclamation marks as the delimiters, the m modifier which matches $ at the end of every newline, and ^ at the start of every new line. So: !^//.*$!m Means ^ at the start of the line // if there are two of these .* match everything $ up to the end of the new line and replace it with nothing. Check the pattern modifiers etc in the manual. HTH ~James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: HELP with Regular Expressions
> if (($hostname) || ($HOSTNAME)) { >$hostname= trim($hostname); >if ($HOSTNAME) > $hostname = trim($HOSTNAME); >if (!eregi("^[-a-z0-9-]+(\.[a-z0-9-]+)*$ ", $hostname)) { > print_error("your your hostname is invalid"); >} >$HOSTNAME = $hostname; > } Things I know are wrong: 1. I don't think you want a - before the a-z 2. You have ()s around only the stuff *AFTER* the first character. So you are losing that stuff in the ()s to be saved in the third argument you're not providing to eregi()... 3. You didn't escape your \ from PHP, nor eregi(). You need , I think. 4. You have a space after the $, which is wrong. 5. You didn't escape the $ from PHP with \ Warning: I hate Regex, and have no idea if fixing these will get you any closer to what you want. -- WARNING [EMAIL PROTECTED] address is an endangered species -- Use [EMAIL PROTECTED] Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]