Compare String Starts With double quotes

Hi , 

I have to check in condition if a response content starts with double quote . How ever proxy is not getting saved and getting below error .  

<Step>
<Name>AM-OK</Name>
<Condition>(response.content |= "\"")</Condition>
</Step>

Error - 

Error in target default. Invalid condition: (message.content |= """) in policy AM-OK. Reason: Malformed expression: Unterminated "

Best Regards,

Patty

 

Solved Solved
0 6 881
1 ACCEPTED SOLUTION

Hey Patty

Sorry for the delay. I experimented a little and I could never encode a double-quote inside the right-hand-side of a simple comparison Condition. Like |= or = or others.

But there is a regex match operator, which accepts the unicode escape for a double quote. This is what worked for me:

 

 <Step>
   <Name>AM-1</Name>
   <Condition>response.content ~~ "(?s)\s*\u0022[A-Z]+\u0022\s*"</Condition>
 </Step>

 

That ~~ is a JavaRegex matcher, in lieu of the simpler |= operator. I can explain its parts:

  • (?s) this is the DOTALL option, tells the regex to match dots and \s to newlines
  • \s* matches zero or more whitespace
  • \u0022 is the unicode escape code for a double-quote, ascii 34. It matches "
  • [A-Z]+ matches one or more uppercase ASCII characters between A and Z, inclusive.
  • \u0022 matches the trailing double quote
  • \s* matches trailing whiltespace, zero or more characters

You can construct a different regex that is simpler or more general, if you like. Maybe something like

 

   <Condition>response.content ~~ "(?s)\s*\u0022.+"</Condition>

 

...which says "any string that starts with some optional whitespace followed by a double quote."

In my tests, the (?s) is essential when matching against response.content, even if the response.content is a single line, or has no newlines. I don't know why.

View solution in original post

6 REPLIES 6

Try

 

<Condition>response.content |= "\u0022"</Condition>

 

Hi Dino , 

response content is "OK" . But this condition is evaluating to false .

<Condition>response.content |= "\u0022"</Condition>

Best Regards,

Patty

let me try it, and get back to you.

Ok . Thank you .

Hey Patty

Sorry for the delay. I experimented a little and I could never encode a double-quote inside the right-hand-side of a simple comparison Condition. Like |= or = or others.

But there is a regex match operator, which accepts the unicode escape for a double quote. This is what worked for me:

 

 <Step>
   <Name>AM-1</Name>
   <Condition>response.content ~~ "(?s)\s*\u0022[A-Z]+\u0022\s*"</Condition>
 </Step>

 

That ~~ is a JavaRegex matcher, in lieu of the simpler |= operator. I can explain its parts:

  • (?s) this is the DOTALL option, tells the regex to match dots and \s to newlines
  • \s* matches zero or more whitespace
  • \u0022 is the unicode escape code for a double-quote, ascii 34. It matches "
  • [A-Z]+ matches one or more uppercase ASCII characters between A and Z, inclusive.
  • \u0022 matches the trailing double quote
  • \s* matches trailing whiltespace, zero or more characters

You can construct a different regex that is simpler or more general, if you like. Maybe something like

 

   <Condition>response.content ~~ "(?s)\s*\u0022.+"</Condition>

 

...which says "any string that starts with some optional whitespace followed by a double quote."

In my tests, the (?s) is essential when matching against response.content, even if the response.content is a single line, or has no newlines. I don't know why.

Thank you Dino . Your solution worked . 

However  it worked when I compared the double quotes from property set . I implemented like this .

<Condition>(message.content != null) and !(message.content =| propertyset.general.doublequote)</Condition>

Best Regards,

Patty.