mercredi 30 octobre 2019

Assign value to variable from ArrayList with regex

this is my first question here and i'm pretty new to programming so sorry for any mistakes.

I need to extract the first 6 characters(ICAO) and assign it to a locale variable from an ArrayList (taken from https://opensky-network.org/apidoc/rest.html) that looks like this:

["1234a5","ABC123","Schlumpfhausen",1572255699,1572255699,8.9886,48.3756,6278.88,false,155.16,216.64,-6.18,null,6484.62,"3026",false,0
"44035c","LDM87NM ","Austria",1572430045,1572430052,9.2009,48.6891,null,true,0,163,null,null,null,"6463",false,0
.
.
.
]

It is required to use java.util.regex to solve this Problem.

String icao=null;

    Pattern icaoPattern = Pattern.compile("([+-]*[a-zA-Z0-9.]*)");
    Matcher matcher = icaoPattern.matcher(sentence.getAircraftJson());

        if(matcher.find()) {
             icao=matcher.group(1);
        }

The outcome should be printed like this:

ICAO: 1234a5 | Callsign: ABC123 | ...
ICAO: 44035c | Callsign: LDM87NM| ...

but all i get is

ICAO: | Callsign: | ...
ICAO: | Callsign: | ...

Thanks

Aucun commentaire:

Enregistrer un commentaire