Re: [wdvltalk] Regular Expressions in PHP
Thanks Dan and Sheila Now that I see where you're coming from I should be able to adapt it to match a lot of the other things I want to change. No doubt I'll be back when I hit problems! MOU � The WDVL Discussion List from WDVL.COM � To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.
Re: [wdvltalk] Regular Expressions in PHP
Dan Parry wrote: Of course to target and replace just the dash you could use preg_replace('/([0-9]+)(-)([0-9]+)/', '$1dash$3', '47-73'); where the word 'dash' is your replacement dash naturally :) Just to 'splain that a little ... $string = '47-73'; $pattern = '/([0-9]+)(-)([0-9]+)/'; $replacement = '$1dash$3'; $new_string = preg_replace($pattern, $replacement, $string); There are three sets of parens in the pattern. They get numbered left to right $1, $2, $3. In the replacement string $1 and $3 are left alone and the $2 is replaced by 'dash'. Another way to write the replacement string that maybe makes this clearer is $replacement = '${1}dash${3}' -- Sheila http://www.shefen.com/ • The WDVL Discussion List from WDVL.COM • To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.
RE: [wdvltalk] Regular Expressions in PHP
Of course to target and replace just the dash you could use preg_replace('/([0-9]+)(-)([0-9]+)/', '$1dash$3', '47-73'); where the word 'dash' is your replacement dash naturally :) HTH Dan > -Original Message- > From: David Blakey [mailto:[EMAIL PROTECTED] > Sent: 25 October 2007 21:57 > To: wdvltalk@lists.wdvl.com > Subject: Re: [wdvltalk] Regular Expressions in PHP > > At 09:37 a.m. 26/10/2007, you wrote: > >I am not that familiar with PHP, but try using [0-9][0-9]-[0-9][0-9] > > If the numbers can be more than two digits long, [0-9]+-[0-9]+ > > Regards, > David > > > The WDVL Discussion List from WDVL.COM > To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] > dl.sparklist.com or > use the web interface http://e- > newsletters.internet.com/discussionlists.html/ >Send Your Posts To: wdvltalk@lists.wdvl.com > To change subscription settings, add a password or view the web > interface: > http://intm-dl.sparklist.com/read/?forum=wdvltalk > > http://www.wdvl.com ___ > > You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] > To unsubscribe send a blank email to leave-26343723- > [EMAIL PROTECTED] > To unsubscribe via postal mail, please contact us at: > Jupitermedia Corp. > Attn: Discussion List Management > 475 Park Avenue South > New York, NY 10016 > > Please include the email address which you have been contacted with. > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release Date: > 23/10/2007 19:39 > No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release Date: 23/10/2007 19:39 • The WDVL Discussion List from WDVL.COM • To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.
Re: [wdvltalk] Regular Expressions in PHP
Oops. ^[0-9]+-^[0-9]+ The WDVL Discussion List from WDVL.COM To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.
Re: [wdvltalk] Regular Expressions in PHP
At 09:37 a.m. 26/10/2007, you wrote: I am not that familiar with PHP, but try using [0-9][0-9]-[0-9][0-9] If the numbers can be more than two digits long, [0-9]+-[0-9]+ Regards, David The WDVL Discussion List from WDVL.COM To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.
Re: [wdvltalk] Regular Expressions in PHP
I am not that familiar with PHP, but try using [0-9][0-9]-[0-9][0-9] HTH, Riva Ross Clutterbuck wrote: Hi all After many years of head-scratching trying to get to grips with Regular Expressions, I've come to a point in a project where I must utilise their power but I'm hitting brick walls already. I've writing a typography parser to convert standard keyboard-inputted characters into their typographical counterparts (quotation marks into curly quotes, proper Em and En dashes, etc.). I think I can identify characters based on patterns but I can't properly replace them. For example, I want to change a standard keyboard dash (the one paired with the underscore) into an Em dash when it's sandwiched between two numbers. Let's say we have in our string 45-78 I can successfully identify that dash with the pattern [0-9]-[0-9] but the string returned will be 5-7 so when I go to replace with my Em dash, it replaces the whole found string, not just the dash, giving 4—8 when I want 45—78 Obviously there's something big time I'm missing, or is my pattern incorrect? I want to identify a dash that is preceded and succeeded by a number, and change the dash only. Any help out there? MOU � The WDVL Discussion List from WDVL.COM � To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/ Send Your Posts To: wdvltalk@lists.wdvl.com To change subscription settings, add a password or view the web interface: http://intm-dl.sparklist.com/read/?forum=wdvltalk http://www.wdvl.com ___ You are currently subscribed to wdvltalk as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] To unsubscribe via postal mail, please contact us at: Jupitermedia Corp. Attn: Discussion List Management 475 Park Avenue South New York, NY 10016 Please include the email address which you have been contacted with.