Regex assert position at beginning of string

Microsoft

I am trying to get the 2 matches found at the beginning of the string. According to this page, you can use \A to match beginning of the line. The re2 engine syntax also permits ^ to assert position to beginning of string. 

In this case I want the first 2 <Param>value</Param>. The expected return value is ["a","b"] but instead the return is [["a","b"],["c","d"]]

 

print extract_all("^<Param>([^<]*)</Param><Param>([^<]*)</Param>", "<Param>a</Param><Param>b</Param><Param>c</Param><Param>d</Param><Param>e</Param>")
print extract_all("\\A<Param>([^<]*)</Param><Param>([^<]*)</Param>", "<Param>a</Param><Param>b</Param><Param>c</Param><Param>d</Param><Param>e</Param>")

 

I know you could use the parse operator, but in this case I need to specify a regex. 

2 Replies

@zaedwa 

 

How about?

 

print Id="<Param>a</Param><Param>b</Param><Param>c</Param><Param>d</Param><Param>e</Param>"
| extend rawExtract = extract_all(@"^<Param>([^<]*)</Param><Param>([^<]*)</Param>", dynamic([1,2]), Id) 
| extend returnFirst = rawExtract[0]
Yes, although that works in this scenario, it doesn't answer why the ^ and \A are not honored in these regex patterns :(