# Expect for a string containing special chars

**URL:** <https://community.postman.com/t/expect-for-a-string-containing-special-chars/44224>\
**Category:** Help Hub\
**Created:** [February 20, 2023, 3:52pm UTC](https://community.postman.com/t/expect-for-a-string-containing-special-chars/44224 "2023-02-20T15:52:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihamina-oney](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mihamina-oney](https://community.postman.com/u/mihamina-oney)\
**Post date:** [February 20, 2023, 3:52pm UTC](https://community.postman.com/t/expect-for-a-string-containing-special-chars/44224/1 "2023-02-20T15:52:31Z")

</div>

Hi all,

I want to assert that this string is in the response:

```auto
5 execution(s) of my-azure-function-dev/function-name failed

```

I test it this way:

```auto
pm.test('Body Content', function() {
        pm.expect(resp[1].message.text).to.contain('5 execution(s) of my-azure-function-dev/function-name failed');
    });

```

I already tried to escape parenthesis, slash, hyphen… but I dont figure out how to match that piece of string.

How to?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 20, 2023, 4:25pm UTC](https://community.postman.com/t/expect-for-a-string-containing-special-chars/44224/2 "2023-02-20T16:25:08Z")

</div>

Can you console log the response element on its own and share a screenshot?  
Or share the error when it fails, which should hopefully tell you what its trying to compare.

```auto
console.log(resp[1].message.text);

```

Or define that element in its own variable for the comparison.

If the response is a string, then no escape characters should be needed.

If I define a string with that text, then the assertion appears to be work ok, so therefore I’m wondering if the issues is with the string response, rather than the assertion.

```auto
let string = "5 execution(s) of my-azure-function-dev/function-name failed"

pm.test('Body Content', function() {
    pm.expect(string).to.contain('5 execution(s) of my-azure-function-dev/function-name failed');
});

pm.test('Body Content', function() {
    pm.expect(string).to.contain('4 execution(s) of my-azure-function-dev/function-name failed');
});

```

First test passes, and second one fails as expected.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/6/962429c6b5e4c097282d194489d64bd2fbbb2270.png)

As the string is fairly long, you could also do this so you can check the two strings in the console log.

```auto
let actualResponse = resp[1].message.text;
let expectedResponse = "5 execution(s) of my-azure-function-dev/function-name failed"

console.log(actualResponse);
console.log(expectedResponse);

pm.test('Body Content', function() {
    pm.expect(actualResponse).to.contain(expectedResponse);
});

```

---

<div class="post-metadata">

**Author:** ![mihamina-oney](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mihamina-oney](https://community.postman.com/u/mihamina-oney)\
**Post date:** [February 21, 2023, 4:36am UTC](https://community.postman.com/t/expect-for-a-string-containing-special-chars/44224/3 "2023-02-21T04:36:33Z")

</div>

Putting it in a variable and using double quotes instead of single ones helped.
