CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
How to get the value after a string

 



dk1979
New User

Feb 8, 2017, 6:48 AM

Post #1 of 3 (3757 views)
How to get the value after a string Can't Post

Hi all,
I have the following string and want to get the value of start_time:

{\"id\":01,\"start_time\":\"1477954800000\",\"stop_time\":\"1485817200000\",\"url\":http:://www.example.com\}

For sure one can get the value by json parsing. However out of pure curiosity I'd like to know how this can be achieved by perl regexp.
I know that if the format was start_time = 1477954800000 one can get the value by the expression :
start_time = (\w+)

But I'm quite confused how to bypass the special charachters \":\"
Can anyone give a hint ?


Laurent_R
Veteran / Moderator

Feb 8, 2017, 7:58 AM

Post #2 of 3 (3753 views)
Re: [dk1979] How to get the value after a string [In reply to] Can't Post

Hi,

an example on how to do it (demonstrated under the Perl debugger):

Code
  DB<1> $s = '{\"id\":01,\"start_time\":\"1477954800000\",\"stop_time\":\"1485817200000\",\"url\":http:://www.example.com\}' 

DB<2> print $1 if $s =~ /start_time\\":\\"(\d+)\\"/;
1477954800000
DB<3>



(This post was edited by Laurent_R on Feb 8, 2017, 7:59 AM)


dk1979
New User

Feb 8, 2017, 9:45 AM

Post #3 of 3 (3746 views)
Re: [Laurent_R] How to get the value after a string [In reply to] Can't Post

Thanks a lot it did the work

In Reply To

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives