SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with regular expression

    I want to extract parts of string that have a dollar sign followed by digits, and
    - either have a space or = in front of $ and
    - space or end of string after digits

    expression in the code below works fine except it doesn't extract $7. What do I need to change to get

    " $1 "
    "=$6 "
    " $7"


    $var = "sometext $1 sometext $2and sometext$4 and sometext($3) sometext=$6 sometext= $7";
    preg_match_all('/[=\s]{1}\$\d+[\s$\z]{1}/',$var,$matches);
    var_dump($matches);

    Thanks for your help.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try

    preg_match_all('~[=\s]\$\d+\s?\b~',$var,$matches);


Bookmarks

Posting Permissions

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