8 Replies Latest reply: Jun 3, 2016 8:45 AM by Austin Perkins RSS

    Regular Expressions in Monarch Complete v13

    Austin Perkins

      I've started working with the regular expression traps and I've found them to be most useful. However, I'm continuing to run into a problem that I am certain there is a fix for, I just can't seem to locate it. The problem is the template length when capturing data of variable size. Please see my example below:

       

      CAS*CO*74*28841.27**253*56.38~

      CAS*PR*1*1216~

      CAS*CO*45*67598.19**253*161.12~

      CAS*PR*2*55.06~

      CAS*PR*2*-17.13

      CAS*PR*2*2.25~

       

      I'm using the following RegEx to capture the CAS*PR rows of data and to grab the numbers before and after the last asterisk: [C][A][S]\*[P][R]\*(\d+)\*(\-?\d+\.?\d*).

       

      The problem is that I need the template to end on the "~" and not be a set length. I've considered widening the template and then just removing the "~" through a calculated field, but I was hoping that Monarch has the ability to extend a template until a certain character was found. Any help would be greatly appreciated.

       

      Austin

        • Re: Regular Expressions in Monarch Complete v13
          Theo Klemming

          Hi Austin

           

          From your regex, it looks like it would capture all numbers down to where it hits the "~" character? You are using "\d*" which means it will capture as many digits there are before a different character turns up, or the value ends. The asterisk means "repeat zero or more times", and it is "greedy", so will repeat as many times as possible. Can you please clarify what your desired result is?

            • Re: Regular Expressions in Monarch Complete v13
              Austin Perkins

              Theo,

               

              Correct, I don't believe the expression is the problem. Let's walk through an example using the data above:

               

              CAS*CO*74*28841.27**253*56.38~

              CAS*PR*1*1216~

              CAS*CO*45*67598.19**253*161.12~

              CAS*PR*2*55.06~

              CAS*PR*2*-17.13

              CAS*PR*2*2.25~

               

              This expression "[C][A][S]\*[P][R]\*(\d)\*(\-?\d+\.?\d*)" will capture lines 2, 4, 5, & 6. In Monarch, the potential selection turns a dark yellow and allows you to right click and create a template from selection. When I do that for the dollar amount (i.e. 1216, 55.06, -17.13, etc), the 1216 will be fully selected but the 55.06 will only partially be selected using the first 4 characters - "55.0" (as would the "-17."). So my goal is to return the entire dollar amount without having to expand my template width and use a calculated field. Does that clarify my problem?

               

              I apologize for detailed language above, the goal was to make it easier to understand for someone other than yourself who might not have your knowledge! I appreciate the help.

               

              Austin

            • Re: Regular Expressions in Monarch Complete v13
              Chris Porthouse

              When dealing with regex, I don't think template width matters.  Using your example, I was able to use this regular expression:

              CAS\*PR\*(?<ID>[0-9]+)\*(?<Amount>[0-9\.\-]+)

               

               

              And i was able to capture:

              eg_ID    eg_Amount

              1    1216.00

              2    55.06

              2    -17.13

              2    2.25

               

              You might need to change the option next to the regular expression trap type to explicit capture

               

              Hope this helps, or let me know if you have any questions about the regex above.

                • Re: Regular Expressions in Monarch Complete v13
                  Austin Perkins

                  Chris,

                   

                  I certainly appreciate you cleaning the expression up for me, I'm still very green with writing clean syntax. I tried your expression and it highlighted both fields (I also checked Explicit Capture - do you care to explain what this does?). I right clicked on the amount and created a field from that capture. However, I'm still only getting four characters in length. Did you create the capture a different way?

                   

                  EDIT:

                  It correctly highlighted the correct amount of characters, it's when I go to create a field is when the length is stagnate.

                   

                  EDIT 2:

                  I found that by simply increasing the template size in the field settings, it included all amounts of varying lengths. I believe it is safe to call this issue solved. Chris, I really appreciate the help on this!

                    • Re: Regular Expressions in Monarch Complete v13
                      Chris Porthouse

                      The explicit capture basically means to capture exactly what is being defined in the regex, so it is not forgiving in regards to case sensitivity, white space, etc.

                       

                      I might take back what I said about the template width not mattering.  You should make it as long as you think you are going to need it.  On my model, I had set it to 11 so the right values were displaying correctly.  If I set it to 4, it would truncate some of the numbers and not give me the right results, which makes sense now that I think about it.

                       

                      The regex is going to grab exactly what you defined.  If the template width is set to 4, then only 4 "characters" and your trap pulled in 8 characters, then only 4 characters from that trap will be used for the field value.  If the template width is set to 100 but the trap pulled in 8 characters, then all 8 characters will be used.

                      • Re: Regular Expressions in Monarch Complete v13
                        Chris Porthouse

                        Lol.  Looks like you figured it out while I was typing my explanation.  Good luck and have fun with learning regular expressions.  They are very powerful once you get used to them.