FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Regular Expressions
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Regular Expressions [message #174032] Fri, 20 May 2011 00:03 Go to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
I have the need for a regular expression. I haven't written one for
more then 20 years, and even then I wasn't good!!

I have a string, $parmStr, that contains a mixture of characters and
digits (0-9). I want to extract all none digits and return a string
with ONLY the digits.

Greatly appreciate it someone could show me what I am looking for.

Thank you very much

Bruce
Re: Regular Expressions [message #174034 is a reply to message #174032] Fri, 20 May 2011 00:51 Go to previous messageGo to next message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma: 0
Member
On Thu, 19 May 2011 17:03:27 -0700 (PDT), in comp.lang.php bruceaj
<bruceaj(at)bellsouth(dot)net>
<900016fb-6002-465a-a332-3ef40519371a(at)e21g2000yqe(dot)googlegroups(dot)com>
wrote:

> | I have the need for a regular expression. I haven't written one for
> | more then 20 years, and even then I wasn't good!!
> |
> | I have a string, $parmStr, that contains a mixture of characters and
> | digits (0-9). I want to extract all none digits and return a string
> | with ONLY the digits.
> |
> | Greatly appreciate it someone could show me what I am looking for.
> |
> | Thank you very much
> |
> | Bruce

A starting point would be:
/[0-9]/
Re: Regular Expressions [message #174038 is a reply to message #174034] Fri, 20 May 2011 01:48 Go to previous messageGo to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
On May 19, 8:51 pm, Jeff North <jnort...@yahoo.com.au> wrote:
> On Thu, 19 May 2011 17:03:27 -0700 (PDT), in comp.lang.php bruceaj
> <bruc...@bellsouth.net>
> <900016fb-6002-465a-a332-3ef405193...@e21g2000yqe.googlegroups.com>
> wrote:
>
>> | I have the need for a regular expression. I haven't written one for
>> | more then 20 years, and even then I wasn't good!!
>> |
>> | I have a string, $parmStr, that contains a mixture of characters and
>> | digits (0-9). I want to extract all none digits and return a string
>> | with ONLY the digits.
>> |
>> | Greatly appreciate it someone could show me what I am looking for.
>> |
>> | Thank you very much
>> |
>> | Bruce
>
> A starting point would be:
> /[0-9]/

Works like a champ!!!

Thanks.....

Bruce
Re: Regular Expressions [message #174040 is a reply to message #174034] Fri, 20 May 2011 02:08 Go to previous messageGo to next message
Daniel Peraza is currently offline  Daniel Peraza
Messages: 6
Registered: September 2010
Karma: 0
Junior Member
On May 19, 8:51 pm, Jeff North <jnort...@yahoo.com.au> wrote:
> On Thu, 19 May 2011 17:03:27 -0700 (PDT), in comp.lang.php bruceaj
> <bruc...@bellsouth.net>
> <900016fb-6002-465a-a332-3ef405193...@e21g2000yqe.googlegroups.com>
> wrote:
>
>> | I have the need for a regular expression. I haven't written one for
>> | more then 20 years, and even then I wasn't good!!
>> |
>> | I have a string, $parmStr, that contains a mixture of characters and
>> | digits (0-9). I want to extract all none digits and return a string
>> | with ONLY the digits.
>> |
>> | Greatly appreciate it someone could show me what I am looking for.
>> |
>> | Thank you very much
>> |
>> | Bruce
>


You may also use filter_var:

<?php
$str = "some_characters_and_number_13453432";
echo filter_var($str, FILTER_SANITIZE_NUMBER_INT); // echoes 13453432
?>

Use what you like most.
Re: Regular Expressions [message #174045 is a reply to message #174032] Fri, 20 May 2011 07:47 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 20/05/2011 2:03, bruceaj escribió/wrote:
> I have the need for a regular expression. I haven't written one for
> more then 20 years, and even then I wasn't good!!
>
> I have a string, $parmStr, that contains a mixture of characters and
> digits (0-9). I want to extract all none digits and return a string
> with ONLY the digits.
>
> Greatly appreciate it someone could show me what I am looking for.

Untested:

preg_replace('/[^\d]+/', '', $parmStr);



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: got allow_url_fopen, still don't travel :)
Next Topic: How to "quote code" in PHP?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 06:04:05 GMT 2024

Total time taken to generate the page: 0.02346 seconds