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



dk1979
New User

Feb 8, 2017, 6:48 AM


Views: 9398
How to get the value after a string

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


Views: 9394
Re: [dk1979] How to get the value after a string

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


Views: 9387
Re: [Laurent_R] How to get the value after a string

Thanks a lot it did the work

In Reply To