Reputation: 133
I would like to extract 2 things from this string: | 2013.10.10 FEL felsz
2013.10.10
(in this case)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:
(.*?<p/\s>.*?)(?=\s)
(.*?<p/("[0-9]+">.*?)(?=\s)
Do you have any suggestions?
Upvotes: 2
Views: 2012
Reputation: 1937
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)
Upvotes: 1
Reputation: 18483
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]+) (.*)
Upvotes: 1
Reputation: 8893
How about:
(?:\d+\.\d+\.\d+\s)(.*)\s
See it in action.
This matches FEL
Some things I took for granted:
Upvotes: 1
Reputation: 11132
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
Upvotes: 1
Reputation: 3446
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.
Upvotes: 1