-1

I have a string like that :

Date:X/X/XX
Time:XX:XX:XX
Speed:Xkm/h
Altitude:XX.Xm
Bat:XX%
maps:google.com/maps?q=YY.YYYYYY,-Z,ZZZZZZ

currently this regex is ok :https://regex101.com/r/5JVdgR/1

But I don't know how I can display Y (latitude variable) and Z (longitude variable) ?

here is an idea of what I search :

 var input = "Date:X/X/XX"              //Here is my input variable
 "Time:XX:XX:XX"
 "Speed:Xkm/h"
 "Altitude:XX.Xm"
 "Bat:XX%"
 "maps:google.com/maps?q=14.215465,-1.256584";

void test() {          //On push, I want to extract group1 (lat ) and group 2 (long) into two variable
setState(() {

  RegExp regExp = new RegExp(            //Here is the regex fonction to extract long, lat
    r"maps:google\.com\/maps\?q=(-?[0-9]+.[0-9]+),(-?[0-9]+.[0-9]+)",
   );
  }
 );
}

@override
Widget build(BuildContext context) {

return new Scaffold(
 appBar: new AppBar(
 ),
 body: new Center(
 child: new Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    new Text(

      $group1,$group2         //I want to display each variables extracted by regex

    ),
  ],
 ),
),
  floatingActionButton: new FloatingActionButton(
  onPressed: test,
  tooltip: 'test',
  child: new Icon(Icons.add),
    ),
   );
  }
}
Nitneuq
  • 3,866
  • 13
  • 41
  • 64

2 Answers2

0

Try Regex: maps:google\.com\/maps\?q=(-?\d+(?:(?:\.|,)\d+)?),(-?\d+(?:(?:\.|,)\d+)?) and get Group1 and Group2 values

Demo

This link has a good example for using Regex in Dart

Matt.G
  • 3,586
  • 2
  • 10
  • 23
0

Assuming that -Z,ZZZZZZ would be -Z.ZZZZZZ with a dot instead of a comma, you could capture your values in 2 capturing groups (-?[0-9]+.[0-9]+).

The value for Y will be in group 1, the value for Z will be in group 2.

maps:google\.com\/maps\?q=(-?[0-9]+.[0-9]+),(-?[0-9]+.[0-9]+)

The fourth bird
  • 154,723
  • 16
  • 55
  • 70