Using .NET Regex in OpenEdge - Forum - OpenEdge General - Progress Community

Using .NET Regex in OpenEdge

 Forum

Using .NET Regex in OpenEdge

This question is answered

Hello,

I'm having trouble rewriting my regular expressions from JavaScript into the .NET library.

I'm trying to use Regex on a HTTP response to pull out a specific portion of text. Currently, I am handling the HTTP request in OpenEdge and using Regex in JavaScript. However, I want to move the Regex portion over to OpenEdge as well, that way I can call one function to make the request and return the matched text without having any logic on the client side.

I have about 30 regular expressions I've written in JavaScript that work just fine. Here is one of them:

new RegExp(/"displayActDeliveryDt":"(\d{1,2}\\u002f\d{1,2}\\u002f\d{4})"/);

And here is the portion of the response that I'm trying to match.

"displayActDeliveryDt":"3\u002f20\u002f2019"

What is the best way to convert my JavaScript regex into a format that is suitable for OpenEdge and the .NET library? Notice that I need to match special characters like the double quote, as well as digits with varying occurrences ({1, 2}, {4}, etc.). Is there a simple conversion process, or will I need to rewrite all of them?

Thanks!

Verified Answer
  • I found my problem.

    When reading the HTTP response as a JsonObject, I was using GetJsonText to retrieve the response as text. However, this would add backslash characters to properly escape special characters such as double quotes. This caused my regex to not match the portion of text I was looking for. To fix this, I used GetLongchar which returned the text without the added characters.

All Replies
  • I found my problem.

    When reading the HTTP response as a JsonObject, I was using GetJsonText to retrieve the response as text. However, this would add backslash characters to properly escape special characters such as double quotes. This caused my regex to not match the portion of text I was looking for. To fix this, I used GetLongchar which returned the text without the added characters.