0

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.

5
  • 1
    It's hard to tell which clues/pointers you need - where are you stuck? Which regex engine are you using? Commented May 17, 2014 at 11:46
  • Added some info to Q. I did not realise there was different RegEx engines, I just know that the product im using allows for RegEx expressions within it. Commented May 17, 2014 at 12:05
  • 1
    There are very big differences between engines, and they directly affect which regex features you can use (one reason why there is a market for a tool like RegexBuddy that helps translating regexes between different "flavors"). Which product are you using? Is there any documentation on it? For example, can you access capturing groups, or does it support lookaround assertions? Commented May 17, 2014 at 12:08
  • Its an Esri product which allows you to perform processing on incoming streams. Docco: resources.arcgis.com/en/help/main/10.2/index.html#//… Although I cant see specific mention of the engine used. Commented May 17, 2014 at 12:17
  • Seems to be a very obscure one "ATL regular expressions". I can't even find that on the Wikipedia page of relevant regex flavors... Commented May 17, 2014 at 12:27

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 ':'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.