Results 1 to 5 of 5

Thread: regex question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    regex question

    Hey I need need to extract numerical value between \" and \"


    So string is like
    $a= '\"123\"';


    thanks.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: regex question

    Code:
    <?php
    $a= '\"123\"';
    $pattern = '/[0-9]+/';
    preg_match($pattern, $a, $matches);
    print_r($matches);
    ?>

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    Re: regex question

    Thanks.

    What if i want to get numerical value between # and # or between [ and ]?


    thanks for help by the way....

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: regex question

    Quote Originally Posted by SambaNeko View Post
    Code:
    <?php
    $a= '\"123\"';
    $pattern = '/[0-9]+/';
    preg_match($pattern, $a, $matches);
    print_r($matches);
    ?>
    While that would work, you are better off looking for the entire string and then pulling the numbers out as a subgroup using brackets.

    /\\"([0-9]+)\\\"/

    $matches[1] would contain the number.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    89

    Re: regex question

    Quote Originally Posted by visualAd View Post
    While that would work, you are better off looking for the entire string and then pulling the numbers out as a subgroup using brackets.

    /\\"([0-9]+)\\\"/

    $matches[1] would contain the number.
    that works better...thanks man.Will report how it goes in final product...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width