2016 Nov 22 8:52 PM
Hello experts,
I need help with the regular expressions. I have tried my best but could not achieve. My requirement is to check a variable for pattern like number + alphabet i.e 12c, 150b, 2500c, 1b Last digit should always be either c or b, there should be only a number before b or c. Please help me in this regard.
Thanks,
Petru
Hello experts,
I need help with the regular expressions. I have tried my best but could not achieve. My requirement is to check a variable for pattern like number + alphabet i.e 12c, 150b, 2500c, 1b Last digit should always be either c or b, there should be only a number before b or c. Please help me in this regard.
Thanks,
Petru
2016 Nov 22 9:12 PM
This can be done by some simple conditions as below.
For e.g. your alphanumeric variable is p_test below logic can be used to check the condition
DATA: lv_len TYPE i,
lv_last TYPE i,
p_test type char20.
CONDENSE p_test.
lv_len = STRLEN( p_test ).
lv_last = lv_len - 1.
IF p_test+0(lv_last) CO '1234567890' AND
( p_test+lv_last(lv_len) EQ 'B' OR p_test+lv_last(lv_len) EQ 'C' ).
.....
...
..
...
ENDIF.
2016 Nov 22 10:04 PM
And you get a short dump - At the end what you are doing for a 15 digit pattern (example: 12345678901234c) is p_test+14(15). You will get an error CX_SY_RANGE_OUT_OF_BOUNDS. Even with this the IF statement should be...
IF p_test+0(lv_last) CO '1234567890' AND
( p_test+lv_last(1) EQ 'B' OR p_test+lv_last(1) EQ 'C' ).
2016 Nov 22 9:47 PM
[[:digit:]]+[bc]or
\d+[bc]or
[0-9]+[bc]Both [[:digit:]] and \d mean the same thing and is essentially the same as [0-9] meaning any number between 0 and 9. The '+' means 1 or more occurrences; if you want zero or more, use '*' instead. The [bc] means either b or c.
2016 Nov 22 10:11 PM
If you want to match e.g. 123c but not a123c then you should add the \b (word boundary) token.
\b[0-9]+[bc]\bBut there are a lot of more possibilities which you can best explore in one of the numerous online regex tester sides like
https://regex101.com/ as regex expressions are not an ABAP topic only
2016 Nov 23 10:17 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |