2014 Jun 18 11:22 AM
Hi All,
I am new to using regular expression and writing the patterns, I am looking to write a pattern for below formats and do a FIND REGEX:
A123456-01-123456789-123 and A123456-01-123456789-ABC
DATA: regex TYPE REF TO cl_abap_regex,
res TYPE match_result_tab,
text TYPE string.
CREATE OBJECT regex
EXPORTING pattern = '\(.\)\1'
simple_regex = 'X'
FIND ALL OCCURRENCES OF REGEX regex IN text RESULTS res.
could you help me write the pattern to check if user has entered string in formats A123456-01-123456789-123 and A123456-01-123456789-ABC
Thank you
Depp
2014 Jun 18 11:34 AM
Try out this snippet.
DATA str TYPE string VALUE 'A123456-01-123456789-123'.
FIND REGEX '^\w\d{6}-\d{2}-\d{9}-.{3}$' IN str.
WRITE / sy-subrc.
str = 'A123456-01-123456789-ABC'.
FIND REGEX '^\w\d{6}-\d{2}-\d{9}-.{3}$' IN str.
WRITE / sy-subrc.
/.
2014 Jun 18 11:34 AM
Try out this snippet.
DATA str TYPE string VALUE 'A123456-01-123456789-123'.
FIND REGEX '^\w\d{6}-\d{2}-\d{9}-.{3}$' IN str.
WRITE / sy-subrc.
str = 'A123456-01-123456789-ABC'.
FIND REGEX '^\w\d{6}-\d{2}-\d{9}-.{3}$' IN str.
WRITE / sy-subrc.
/.
2014 Jun 18 6:01 PM
It appears you wanted separate regex patterns that match the given strings.
If that is the case, '^\w\d{6}-\d{2}-\d{9}-\d{3}$' would be for the one ending with 123, and '^\w\d{6}-\d{2}-\d{9}-\w{3}$' would be for the one ending with ABC.
2014 Jun 26 10:57 AM
Hi Manish,
First of all sorry for getting back so late..was stuck with project delivery...and Thank you for your solution. Only one scenario failed i.e., I didn't mention that the value 01 in the examples, is constant in strings A123456-01-123456789-123 and A123456-01-123456789-ABC.
which means it has to be always 01 any other value than 01 the sy-subrc should not be zero.
I will also be thankful if you could share me the document(s) which help us write the above patterns( '^\w\d{6}-\d{2}-\d{9}-\d{3}$' ; '^\w\d{6}-\d{2}-\d{9}-\w{3}$' ).
In the meanwhile I will also do some R&D with your reply to solve the failed scenario.
Regards,
Depp
2014 Jun 26 12:03 PM
Use this snippet then.
'^\w\d{6}-01-\d{9}-.{3}$'
To learn this, you can read F1 help on REGEX keyword, play around with program DEMO_REGEX_TOY and search internet for regular expression examples.
2014 Jul 02 1:42 PM