-1

I have a object "news" that have the property "url".

I want to use regex to filter out all the objects that have the "url" property ENDING with a specific value, in this case "news.aspx". That is, I want the conditional only to look at the end of that property, and not the whole string. Array operator "endsWidth()" has no IE11 support frankly, and thats why I'm using regex instead.

I'm trying to use Regex to filter out a specific value. Below will not filter out but instead give me all the objects where url ends with "news.aspx"

newsArticles.filter(n => /news.aspx$/.test(n.url))

I have search and tried to modify it so it instead filter out, like:

newsArticles.filter(n => ^(/?!news.aspx$/).test(n.url))

But it doesnt work.

9
  • .filter(n => n.url != 'news.aspx')? Commented Jun 6, 2019 at 22:13
  • Some other suggestions. Commented Jun 6, 2019 at 22:14
  • 1
    Why such a struggle ? Match all lines that don't end in news.aspx : newsArticles.filter(n => /.+$(?<!news\.aspx)/i) regex101.com/r/90htnL/1 Commented Jun 6, 2019 at 22:45
  • 1
    For the JavaScript challenged it is this newsArticles.filter(n => /^(?!.*news\.aspx$).+$/i) regex101.com/r/R4YSju/1 Commented Jun 6, 2019 at 22:57
  • 1
    Just add a !: newsArticles.filter(n => !/news.aspx$/.test(n.url)) Commented Jun 6, 2019 at 22:59

1 Answer 1

0
newsArticles.filter(n => !/news\.aspx$/.test(n.url))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.