Question

I would like to extract 2 things from this string: | 2013.10.10 FEL felsz

  1. regex -> Date field -> the needed value will be only the 2013.10.10 (in this case)
  2. regex -> String between 2013.10.10 and felsz string -> the needed value will be only the FEL string (in this case).

I tried with the following regexes as with not too much success:

  1. (.*?<p/\s>.*?)(?=\s)
  2. (.*?<p/("[0-9]+">.*?)(?=\s)

Do you have any suggestions?

Was it helpful?

Solution

As mentioned in comments, since ABAP doesn't allow non-greedy match with *?, if you can count on felsz occurring only immediately after the second portion you want to match you could use:

(\d{4}\.\d\d\.\d\d) (.*) felsz

(PS: Invalidated first answer: in non-ABAP systems where *? is supported, the following regex will get both values into submatches. The date will be in submatch 1 and the other value (FEL in this case) will be in submatch 2 : `(\d{4}.\d\d.\d\d) (.*?) felsz)

OTHER TIPS

Is "felsz" variable? Can the white space vary? Can your date format vary? If not:

\| (\d{4}\.\d{2}\.\d{2}) (.*?) felsz

Otherwise:

\|\s+?(\d{4}\.\d{2}\.\d{2})\s+?(.*?)\s+?[a-z]+

Then access capture groups 1/2.

The regex

\d+\.\d+\.\d+

matches 2013.10.10 in the given string. Explanation and demonstration: http://regex101.com/r/bL7eO0

(?<=\d ).*(?= felsz)

should work to match FEL. Explanation and demonstration: http://regex101.com/r/pV2mW5

If you want them in capturing groups, you could use the regex:

\| (\d+\.\d+\.\d+) (.+?) .*

Explanation and demonstration: http://regex101.com/r/rQ6uU4

How about:

(?:\d+\.\d+\.\d+\s)(.*)\s See it in action.

This matches FEL

Some things I took for granted:

  1. the date always comes first and is a mix of numbers and periods
  2. the date is always followed by a space
  3. the word to capture is always followed by a space
  4. the word to capture never contains a space

Assuming that FEL is always a single word (that is, delimited by a space), you could use the following expression:

(\d{4}\.\d\d\.\d\d) ([^\s]+) (.*)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top