www.webdeveloper.com
Results 1 to 4 of 4

Thread: need help for nice code of parser of defined string

  1. #1
    Join Date
    Nov 2012
    Posts
    8

    need help for nice code of parser of defined string

    Hello everybody,
    I am about to do a parser for following type of strings:
    FROM
    "0.150 C03939::cyt" + "2 ORieske_B6::cyt" => "C05744::cyt" + "38 P680::cyt" + "C00229::cyt"
    TO
    0.150 "C03939::cyt" + 2 "ORieske_B6::cyt" => "C05744::cyt" + 38 "P680::cyt" + "C00229::cyt"

    It's mean that I need to get numbers out of double quotes. I believe me to be able to do that with some "for" and "if" statments, but I am trying to find some elegant solution (like 5-10 rows). Can someone help me pls?

    Thanks very much.

  2. #2
    Join Date
    May 2003
    Posts
    599
    Are all your quoted strings always going to end in '::cyt'?
    We do precision guesswork

  3. #3
    Join Date
    Nov 2012
    Posts
    8
    Quote Originally Posted by hastx View Post
    Are all your quoted strings always going to end in '::cyt'?
    No,
    there is just always "::".$str."\"", where $str does not contain space (" ").

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,247
    PHP Code:
    <?php

    $string 
    '"0.150 C03939::cyt" + "2 ORieske_B6::cyt" => "C05744::cyt" + "38 P680::cyt" + "C00229::cyt"';

    $regex '#(?<= |^)"(\S+)\s+(\S+::\S+)"(?= |$)#';
    $string preg_replace($regex"$1 \"$2\""$string);
    echo 
    $string;
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles