jakc
jakc

Reputation: 1171

Extract values from this string?

I have the following string of text.

LOCATION: -20.443 122.951
TEMPERATURE: 54.5C
CONFIDENCE: 50%
SATELLITE: aqua
OBS TIME: 2014-05-06T05:30:30Z
GRID: 1km

This is being pulled from a feed, and the fieldnames stay the same, but the values differ.

I have been trying to get my head around regular expressions and find a way to pull:

  1. 54.5 (temperature)
  2. 50 (confidence)

So I need two separate regular expressions that can pull the above from the original string. Any clues or pointers would be great.

I am doing this within a product that allows me to point to strings and can apply regular expressions to the strings so that values can be extracted and written to new fields.

Upvotes: 0

Views: 58

Answers (2)

Tim Pietzcker
Tim Pietzcker

Reputation: 336108

ArcGIS appears to be using a very limited regex engine. It looks like it doesn't even support capturing groups, let alone lookaround. So I guess you need to try the following:

TEMPERATURE: ([0-9.]+)C

will match the TEMPERATURE entry and

CONFIDENCE: ([0-9]+)%

will match the CONFIDENCE entry.

If you're lucky, you can then access the relevant part of the match via the special variable \1 or $1 (which would then contain "54.5" and "50", respectively.

If that's not possible, you'll have to "manually" trim the first 13/12 characters from the left side from the string as well as the rightmost character.

Upvotes: 2

bob_saginowski
bob_saginowski

Reputation: 1429

You can split this text with delimiter- new line. As result you get an array. Than you can split the elements of the array with delimiter ':'

Upvotes: 1

Related Questions