Sign in to follow this  
Followers 0
Fitgo

StringRegExp Help

15 posts in this topic

I take this value, in lng: 16.2478996
This is the string:
"bounds" : {
               "northeast" : {
                  "lat" : 39.3137195,
                  "lng" : 16.2478996
               },
               "southwest" : {
                  "lat" : 39.3137169,
                  "lng" : 16.2478815
               }
            },
            "location" : {
               "lat" : 39.3137169,
               "lng" : 16.2478996
            },
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 39.3150671802915,
                  "lng" : 16.2492395302915
               },
               "southwest" : {
                  "lat" : 39.3123692197085,
                  "lng" : 16.24654156970849
               }
            }

The value is in here (in lng):

            "location" : {
               "lat" : 39.3137169,
               "lng" : 16.2478996

Let's say "lat" and "lon" can take on any value, just that it is a number with a dot and then another number. Example:

1.31

21.5790

33.12

and more...

Share this post


Link to post
Share on other sites



So what is your question? That may help somebody answer it.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I do not know how to take this value: 16.2478996

Is contained in "lng" in "location".

Consists of numbers, a point and then other numbers.

Thanks. :D

Edited by Fitgo

Share this post


Link to post
Share on other sites

Hi,

#include <Array.au3>

$s = FileRead("t.txt")

$a = StringRegExp($s, '(?s)"location"(?:.*?)(\d+.\d+),', 3)

_ArrayDisplay($a)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Firefox,

You've got a typo so you get the lat  :)

$a = StringRegExp($s, '(?s)"location".*?lng.*?([\d.]+)', 3)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

oh yes, I was going to post the regex to get the lat and the lng until I saw he wanted only the lng.

And thanks for your correction, much better :)

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#include <Array.au3>

_Restituisci_latitudine("Via Lazio, 36, Cosenza")

Func _Restituisci_latitudine($Indirizzo)
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
   $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $Indirizzo & "&sensor=false")
   $oHTTP.Send()
   $Codice_pagina = $oHTTP.Responsetext

   ; ConsoleWrite($Codice_pagina)

   $Stringa = StringRegExp($Codice_pagina, '(?s)"location"(?:.*?)(\d+.\d+),', 3)
   For $i = 0 To UBound($Stringa) - 1
      Return $Stringa[$i]
   Next
EndFunc

Thank you very much, but I tried that and it does not work.

jdelaney, it seems excessive use external UDF.

Share this post


Link to post
Share on other sites

Thanks :D but even whit

(?s)"location".*?lng.*?([\d.]+)

it doesn't work.

#include <Array.au3>

_Restituisci_latitudine("Via Lazio, 36, Cosenza")

Func _Restituisci_latitudine($Indirizzo)
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
   $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $Indirizzo & "&sensor=false")
   $oHTTP.Send()
   $Codice_pagina = $oHTTP.Responsetext

   ; ConsoleWrite($Codice_pagina)

   $Stringa = StringRegExp($Codice_pagina, '(?s)"location".*?lng.*?([\d.]+)', 3)
   For $i = 0 To UBound($Stringa) - 1
      Return $Stringa[$i]
   Next
EndFunc

I just need a value so do not know whether it is right to use For... :3

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It does work, and btw you can only make one return.

$s = _Restituisci_latitudine("Via Lazio, 36, Cosenza")

ConsoleWrite("lng : " & $s)

Func _Restituisci_latitudine($Indirizzo)
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
   $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $Indirizzo & "&sensor=false")
   $oHTTP.Send()
   $Codice_pagina = $oHTTP.Responsetext

   ConsoleWrite($Codice_pagina)

   $Stringa = StringRegExp($Codice_pagina, '(?s)"location"(?:.*?)(\d+.\d+),', 3)
   Return $Stringa[0]
EndFunc
Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Confirmation  :)

#include <Array.au3>

$s = _Restituisci_latitudine("Via Lazio, 36, Cosenza")
_ArrayDisplay($s)

Func _Restituisci_latitudine($Indirizzo)
   $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
   $oHTTP.Open("GET", "http://maps.google.com/maps/api/geocode/json?address=" & $Indirizzo & "&sensor=false")
   $oHTTP.Send()
   $Codice_pagina = $oHTTP.Responsetext

   Return StringRegExp($Codice_pagina, '(?s)location".*?lat.*?([\d.]+).*?lng.*?([\d.]+)', 3)
EndFunc

You can make one return only but this can be an array  ;)

Edited by mikell

Share this post


Link to post
Share on other sites

Very thanks :)

Share this post


Link to post
Share on other sites

               "lat" : 36.1805194,
               "lng" : -86.72654829999999

Before the number there could also be a hyphen. How do I resolve with:

(?s)location".*?lat.*?([\d.]+).*?lng.*?([\d.]+)

?

Thanks. :)

Share this post


Link to post
Share on other sites

In this context it's unlikely that Google would have fun with you by returning 5-6.7-523...47-5

To remove the possibility of wrong input, use this instead:

(?s)location".*?lat.*?(-?d+(?:.d+)?).*?lng.*?(-?d+(?:.d+)?)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0