‎2007 Jun 27 2:57 PM
Hi everybody.
I have to do a replace using a regular expression to do this:
For example in a XML string, clear al the occurrences of the string like this:
I want to delete all this occurrence.
<field>0000-00-00</field>
I employ a replace like this:
DATA: reg_exp type string.
reg_exp = '<>0000-00-00</>'.
REPLACE ALL OCURRENCES OF REGEX reg_exp IN XML_STRING with ''.
It return me a sy-subrc = 4.
I don't know how to delete all this substring, or witch reg_exp pattern should i employ.
Anybody can help me??
‎2007 Jun 27 3:00 PM
replace them with SPACE or ' '. not ''.
AFTER that do:
condense XML_STRING.
‎2007 Jun 27 3:00 PM
replace them with SPACE or ' '. not ''.
AFTER that do:
condense XML_STRING.
‎2007 Jun 27 3:02 PM
HI,
Write like this
REPLACE ALL OCURRENCES OF reg_exp IN XML_STRING with SPACE.
Regards
Sudheer
‎2007 Jun 27 3:57 PM
No. I wanna know if my regex is ok.
Please, could you check if my search pattern is correct?????'???
‎2007 Jun 27 3:17 PM
‎2007 Jun 27 3:18 PM
Hi Miguel,
Look at this sample code with output.
DATA: T(10) VALUE 'abcdefghij',
STRING LIKE T,
STR1(4) VALUE 'cdef',
STR2(4) VALUE 'klmn',
STR3(2) VALUE 'kl',
STR4(6) VALUE 'klmnop',
LEN TYPE I VALUE 2.
STRING = T.
WRITE STRING.
REPLACE STR1 WITH STR2 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR3 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR4 INTO STRING.
WRITE / STRING.
The output appears as follows:
abcdefghij
abklmnghij
abklmnefgh
abklghij
abklmnopgh
Note how, in the last line, the field STRING is truncated on the right. The search pattern 'cdef' of length 4 is replaced by 'klmnop' of length 6. Then, the rest of the field STRING is filled up to the end of the field.
<b>Reward points, if helpful.</b>
Regards,
Atin