04-07-2011 5:47 PM
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.
04-07-2011 6:16 PM
check the program DEMO_REGEX_TOY to find a regular expression you can use
04-07-2011 5:59 PM
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.
04-07-2011 6:11 PM
04-07-2011 6:49 PM
Then try the following.
FIND ALL OCCURRENCES OF REGEx '((tes)|(reg))' IN lv_str IGNORING CASE
RESULTS result_tab.
04-07-2011 6:58 PM
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.
04-07-2011 7:17 PM
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
04-11-2011 10:48 PM
If you found an answer please put that here and close the thread.
04-07-2011 6:16 PM
check the program DEMO_REGEX_TOY to find a regular expression you can use
04-07-2011 6:30 PM
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.
04-07-2011 6:53 PM
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
04-08-2011 5:35 AM
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