Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Questions for REGEX

Former Member
0 Likes
501

Hi, Experts.

I'd like to use 'FIND' and 'REGEX' for seaching certain records in an internal table.

The Search condition is this. 'NN-'. Starts with 'N' and then the string has '-N'.

I used 'FIND' like this. 'IFND regex 'N*\Q-N\E' in dobj.

But, I couldn't get a result that I want. This Returns some garbages that it didn't start with 'N' and include '-N'.

What should I use REGEX to solve this Problem.

The following string is example.

'New-Notepad'.

Thanks.

1 ACCEPTED SOLUTION
Read only

rainer_hbenthal
Active Contributor
0 Likes
468

You should read the documentation for regexe first

^N.*-N

3 REPLIES 3
Read only

Former Member
0 Likes
468

Hi,

The below regex will solve your problem.

FIND REGEX 'N\C*-N' IN dobj.
IF sy-subrc = 0.
"Match found
ELSE.
"NO Match Found
ENDIF.

Check and revert back.

Regards

Karthik D

Read only

rainer_hbenthal
Active Contributor
0 Likes
469

You should read the documentation for regexe first

^N.*-N

Read only

former_member212005
Active Contributor
0 Likes
468

I think what you have used is right!

Please refer the below codes for more details....You only have to add the matching offset and matching length addition...


DATA: lv_string TYPE string.
DATA: moff TYPE i,
      mlen TYPE i.
lv_string = 'Newotepad-N'.

FIND REGEX 'N*-N*' IN lv_string MATCH OFFSET moff
     MATCH LENGTH mlen.

WRITE:/ moff,
 mlen.

It gave me the output as offset '9' and length '2'....which is right...

Try and let me know...