Discussion Why does the following pattern work with one of my udf vs the other in Excel
https://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2804829#M116303
<P>First, I'd like to give credit to the post answer that helped me greatly, <A href="https://techcommunity.microsoft.com/t5/excel/excel-vba-vb-5-5-regex-help-getting-count-and-value/m-p/2800958#M116106" target="_self">here</A></P><P> </P><P>Another post that helped me was <A href="https://stackoverflow.com/a/22542835/139698" target="_self">here</A> on StackOverflow.</P><P> </P><P> </P><P>The StackOverflow UDF works with the following pattern "12abc" with "^[0-9]{1,3}]".</P><P> </P><P>Now, the post answer does not work with this particular pattern and example...</P><P> </P><P>Any thoughts?</P><P> </P><P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rodsan724_0-1633144462065.png" style="width: 400px;"><img src="https://techcommunity.microsoft.com/t5/image/serverpage/image-id/314539i74184C238B149CA7/image-size/medium?v=v2&px=400" role="button" title="rodsan724_0-1633144462065.png" alt="rodsan724_0-1633144462065.png" /></span></P><P> </P><P> </P>Sat, 02 Oct 2021 14:13:33 GMTrodsan7242021-10-02T14:13:33ZWhy does the following pattern work with one of my udf vs the other
https://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2804829#M116303
<P>First, I'd like to give credit to the post answer that helped me greatly, <A href="https://techcommunity.microsoft.com/t5/excel/excel-vba-vb-5-5-regex-help-getting-count-and-value/m-p/2800958#M116106" target="_self">here</A></P><P> </P><P>Another post that helped me was <A href="https://stackoverflow.com/a/22542835/139698" target="_self">here</A> on StackOverflow.</P><P> </P><P> </P><P>The StackOverflow UDF works with the following pattern "12abc" with "^[0-9]{1,3}]".</P><P> </P><P>Now, the post answer does not work with this particular pattern and example...</P><P> </P><P>Any thoughts?</P><P> </P><P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rodsan724_0-1633144462065.png" style="width: 400px;"><img src="https://techcommunity.microsoft.com/t5/image/serverpage/image-id/314539i74184C238B149CA7/image-size/medium?v=v2&px=400" role="button" title="rodsan724_0-1633144462065.png" alt="rodsan724_0-1633144462065.png" /></span></P><P> </P><P> </P>Sat, 02 Oct 2021 14:13:33 GMThttps://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2804829#M116303rodsan7242021-10-02T14:13:33ZRe: Why does the following pattern work with one of my udf vs the other
https://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805297#M116326
<P><LI-USER uid="1165219"></LI-USER> </P>
<P>Please attach a sample workbook with the code and some dummy data, so that we don't have to do all the work.</P>Sat, 02 Oct 2021 09:40:13 GMThttps://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805297#M116326Hans Vogelaar2021-10-02T09:40:13ZRe: Why does the following pattern work with one of my udf vs the other
https://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805705#M116350
Good point, added to OP.Sat, 02 Oct 2021 14:14:06 GMThttps://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805705#M116350rodsan7242021-10-02T14:14:06ZRe: Why does the following pattern work with one of my udf vs the other
https://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805764#M116355
<P><LI-USER uid="1165219"></LI-USER> </P>
<P>Thanks!</P>
<P>The getTargetValueV2 function tries to return the first of the <STRONG>submatches</STRONG> of the last <STRONG>match</STRONG>.</P>
<P>A <STRONG>submatch</STRONG> is a value corresponding to an expression between parentheses in the <STRONG>pattern</STRONG>.</P>
<P> </P>
<P>The formula in B1 uses "target1 = (\d+)" as <STRONG>pattern</STRONG>. It has one expression in parentheses: (\d+).</P>
<P>The <STRONG>matches</STRONG> collection contains two items: "target1 = 1234" and "target1 = 5678". The numeric strings 1234 and 5678 are the result of the expression (\d+), so they are the <STRONG>submatches</STRONG>.</P>
<P> </P>
<P>The formula in B2 uses ^[0-9]{1,3} as <STRONG>pattern</STRONG>. This does not have an expression in parentheses, so there will be no <STRONG>submatches</STRONG>.</P>
<P>You could change the <STRONG>pattern</STRONG> to ^([0-9]{1,3}) so that the formula becomes</P>
<P> </P>
<LI-CODE lang="excel-formula">=getTargetValueV2(A2,"^([0-9]{1,3})")</LI-CODE>
<P> </P>
<P> The formula will then return 12.</P>Sat, 02 Oct 2021 15:02:45 GMThttps://techcommunity.microsoft.com/t5/excel/why-does-the-following-pattern-work-with-one-of-my-udf-vs-the/m-p/2805764#M116355Hans Vogelaar2021-10-02T15:02:45Z