Garuuk
Garuuk

Reputation: 2244

reg expression with backslash and certain chars

I'm trying to remove all escape characters returned from this steam json

tings_block\">\r\n\t\t\t<div class=\"market_listing_right

i'm trying to pull out the \r and \n so i'm left with

tings_block"><div class="market_listing_right

When I try

[^\\r] 

It pulls out the backslashes but it also pulls out all the other r's that aren't next to a backslash. How can I achieve this?

Upvotes: 0

Views: 60

Answers (2)

Maak
Maak

Reputation: 5038

This would remove all \r, \n, \t and all simple \ in your string.

var regex = /\\[rnt]?/g;
str.replace(regex, "");

Upvotes: 2

Arif Burhan
Arif Burhan

Reputation: 505

Use:

/(\\n)|(\\r)/

Which is \n OR \r

Upvotes: 0

Related Questions