NAV Regular Expression - Match Transformation

jordi79
Member Posts: 280
Hi,
I notice something peculiar with the NAV Standard RegEx - match found in Page Transformation Rule Card (1238). This NAV standard RegEx Match skips the 1st match result.
e.g.

I expect to see
As match results. But NAV RegEx match skips the 1st match result.
When the same Regex expression in tested in:
regexr.com/73md2
It matches all 5 lines.
I notice something peculiar with the NAV Standard RegEx - match found in Page Transformation Rule Card (1238). This NAV standard RegEx Match skips the 1st match result.
e.g.

I expect to see
data: 1
data: 2
data: 3
data: 4
data: 5
As match results. But NAV RegEx match skips the 1st match result.
When the same Regex expression in tested in:
regexr.com/73md2
It matches all 5 lines.
0
Best Answer
-
That function is not designed for a multi line string.
The way it is designed it expects one match. It then skips the first capture of the match group (which is the entire match). It then returns a concatenation of the capture groups of the regex. (You do not have any capture groups in your regex). Instead, what you get is the remaining matches as a whole.
If you added a capture group for wat you probably expect to get back, like so:(?=.*data)(.*)
the result of the transformation would bedata: 1data: 2data: 2data: 2data: 3data: 3data: 4data: 4data: 5data: 5
(= first capture group of first match + 2nd match + first capture group of 2nd match + ...)
You will not get the line breaks in the result, unless you change the options, as the dot operator does not match line break characters by default.
Note: the terminology might be confusing, as "capture group" above reffers to the element of the regular expression, not to some .NET data structure / class0
Answers
-
That function is not designed for a multi line string.
The way it is designed it expects one match. It then skips the first capture of the match group (which is the entire match). It then returns a concatenation of the capture groups of the regex. (You do not have any capture groups in your regex). Instead, what you get is the remaining matches as a whole.
If you added a capture group for wat you probably expect to get back, like so:(?=.*data)(.*)
the result of the transformation would bedata: 1data: 2data: 2data: 2data: 3data: 3data: 4data: 4data: 5data: 5
(= first capture group of first match + 2nd match + first capture group of 2nd match + ...)
You will not get the line breaks in the result, unless you change the options, as the dot operator does not match line break characters by default.
Note: the terminology might be confusing, as "capture group" above reffers to the element of the regular expression, not to some .NET data structure / class0 -
I saw the code on how it was written in NAV for the standard NAV RegExMatch, and I cannot understand what is the practical reasons on why it was written that way.
I ended up writing a simpler custom transformation, and it ended up behaving like how https://regexr.com/ behaves.dnMatches := dnRegEx.Matches(SearchString,TransformationRule."Custom Parameter 1");
FOR i := 0 TO dnMatches.Count - 1 DO BEGIN
OutputText += dnMatches.Item(i).Value;
END;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions