Application Development 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: 

Search a pattern in a table

Former Member
0 Kudos

Dear REGEX gurus.

I have an internal table. I want to search for a pattern in it.

Simple example:

DATA: lv_str TYPE string.

DATA result_tab TYPE match_result_tab.

lv_str = ' testing regex pattern ' .

FIND ALL OCCURRENCES OF REGEX 'tesreg*' IN lv_str "IGNORING CASE

RESULTS result_tab.

IF sy-subrc = 0.

WRITE: 'okay'.

ELSE.

WRITE: 'not okay'.

ENDIF.

But if I put REGEX '*tes' -> I get syntax error.

If I remove it, my results are not correct - nothing is found, when there is a text - testing regex which matches ''tesreg'.

What is going wrong here?

Basically I will make a pattern like this: concatenate 'IT_DATA' lv_num '*' into lv_pat. find all occurences of regex lv_pat in table lt_str ignoring case results ...

How to make it work because putting * in front of pattern gives syntax error - but I want it as there may be leading spaces.

and anyway, this regex is not working for me

Thanks in adv.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

check the program DEMO_REGEX_TOY to find a regular expression you can use

10 REPLIES 10

former_member191735
Active Contributor
0 Kudos

The check of the regular expression "tes+reg" resulted in an error in the

character offset 0. This could be caused by incorrect brackets, the

empty character sequence, or the use of an operator that is not

supported so far..

This should work if you change to

FIND ALL OCCURRENCES OF REGEX 'tes+reg*' IN lv_str

RESULTS result_tab.

Remove * from first position. Check out the help for Valid regular expression and also for Character String Patterns.

0 Kudos

Thanks Sampath, but already tried that and it does not work.

0 Kudos

Then try the following.

FIND ALL OCCURRENCES OF REGEx '((tes)|(reg))' IN lv_str IGNORING CASE

RESULTS result_tab.

0 Kudos

Thanks Sampath. But this one is an OR condition, right? It is giving incorrect results as if I remove Test, still it is working as REG word is there.

0 Kudos

Yes it is a OR condition and it should work even if you remove 'tes' as you are using as a pattern.

There are different type of Regular expressions. couple of them are

Single Character strings and Character string patterns.

are you looking for a pattern or exact match?

by the way, you can use '^tes*' for space infornt of test.

Edited by: Sampath Kumar on Apr 7, 2011 12:23 PM

0 Kudos

If you found an answer please put that here and close the thread.

Former Member
0 Kudos

check the program DEMO_REGEX_TOY to find a regular expression you can use

0 Kudos

Thanks Sebastian. But I know of this program and I could not find any expression meeting my needs although it sounds so simple

Already tried for 2 hours.. I guess it would be a minute's job for a REGEX expert.

0 Kudos

Im not an expert either, but try replacing

FIND ALL OCCURRENCES OF REGEX '*tes*reg*' IN lv_str "IGNORING CASE

with

FIND ALL OCCURRENCES OF REGEX '.*tes.*reg.*' IN lv_str "IGNORING CASE

add a dot (.) before *

this [link|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9222ea17-0a01-0010-4a85-a71ba4284b9d?quicklink=index&overridelayout=true] may help

edited: I think that regex that Sampath Kumar posted is better than add a dot

Edited by: Sebastian Bustamante on Apr 7, 2011 7:56 PM

Former Member
0 Kudos

Hi,

If nothing works, I think you can try with the patterns for comparing strings like CP. In your case I guess CP will work.

You can refer this link for more details.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm

Also for finding character strings, you can refer the below link.

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb33cc358411d1829f0000e829fbfe/content.htm