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

REGEX help

rajsg1202
Explorer
0 Likes
1,350

Hi, am new to REGEX. Can someone suggest REGEX for the below string.

{ "HHHH": { "@H1": "11111", "@H2": "22222", "AA": [ { "@A1": "A1A1", "A2A2": "A3A3" } , { "@A2": "A1A1", "A2A2": "A3A3" } } } ], "BB": [ { "@B1": "A1A1", "A2A2": "A3A3" } , { "@B2": "A1A1", "A2A2": "A3A3" } ], "CC": [ { "@C1": "A1A1", "A2A2": "A3A3" } , { "@C2": "A1A1", "A2A2": "A3A3" } ] } }

From the above, how can I pick only "BB": [ { "@B1": "A1A1", "A2A2": "A3A3" } , { "@B2": "A1A1", "A2A2": "A3A3" } ], I have REGEX like below Find REGEX ' "BB": \{\W.*("CC") ' This is picking match like "BB": [ { "@B1": "A1A1", "A2A2": "A3A3" } , { "@B2": "A1A1", "A2A2": "A3A3" } ], "CC". How can avoid the "CC"?

5 REPLIES 5
Read only

BaerbelWinkler
SAP Champion
SAP Champion
1,199

Hi Raj,

as you are new to REGEX you may want to "play" with this SAP-provided program:

DEMO_REGEX_TOY

It explains the various REGEX options and lets you try things out.

Hope this helps!

Cheers

Bärbel

Read only

0 Likes
1,199

Hi Barbel,

Thanks, yes I tried and got this one "BB": \{\W.*("CC") ' . Still trying to find how can I avoid "CC" from the find mat

Read only

former_member1716
Active Contributor
0 Likes
1,199

Hello rajsg1202,

In addition to the above response, recommend you to go through below blog as well.

REGEX

Regards!

Read only

Sandra_Rossi
Active Contributor
1,199

Hey, but it's JSON !

So, don't use Regex, parse the JSON.

See the many questions and answers in the forum.

EDIT: if you want to use a JSONpath in ABAP, sorry it doesn't exist. If you want something close, you have to convert the JSON to XML (CALL TRANSFORMATION) and use:

  • either XPath (method SET_EXPRESSION of CL_XSLT_PROCESSOR)
  • or a very simplified version of XPath named "iXML path", which allows to get the first element of a path, but it doesn't allow to get the Nth element, but if you reach an element via a path, you may then iterate children with iXML methods. For using iXML path, convert the XML into iXML with the function module SDIXML_XML_TO_DOM, then use the method FIND_FROM_PATH of IF_IXML_DOCUMENT.
Read only

0 Likes
1,199

Hi Sandra,

Thanks. some of I am not timely alerts to check the answer.

My requirement is to pick up like jsonpath ( Ex: you may check in Jsonpath.com, $.phoneNumbers[:2]) . If I parse it to ABAP, further I have to pick up specific object and again parse the object to JSON (final output). Hence thought of using JSON Path.

Can you suggest if my approach is right?

Thanks,

Raj