question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Feature - Negative Regex

See original GitHub issue

Hi, first of all, really appreciate all the effort on this fantastic library.

I’d like to suggest what I think is a minor improvement…a negative regex test.

Rationale: It can be quite complex to write the inverse of a regex (negative look ahead etc) and would be much simpler to have the ability to negate the result of the match.

Suggestion: Rather than change the current API, I would suggest negex( regex, message) but entirely up to you.

Apologies if there is another idomatic way of achieving the same outcome.

Background: I’m using tiptap as a Wysiwyg editor. When it’s input is empty, rather than "", it returns "<p></>". I want to error if the regex does not match /^<p><\/>$/, rather than if it does. Currently I preprocess the input to coerce "<p></>" to "".

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
colinhackscommented, May 22, 2022

I’d suggest calling this method .not to be in closer agreement with .and and .or.

Though I’m down to include .negex as well - cool name 😃

0reactions
stale[bot]commented, Jul 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to negate the whole regex? - Stack Overflow
Positive lookarounds can be used to assert that a pattern matches. Negative lookarounds is the opposite: it's used to assert that a pattern...
Read more >
New RegEx Features with Examples - Level Up Coding
Features introduced in ES2018 — “s” dotAll Flag, Named capture groups, Lookbehind assertions, and Unicode property escapes. · “s” ( dotAll ) flag ......
Read more >
Lookahead and Lookbehind Zero-Length Assertions
Negative lookahead is indispensable if you want to match something not followed by something else. When explaining character classes, this tutorial ...
Read more >
Lookahead and Lookbehind Tutorial—Tips &Tricks - RexEgg
This uses a lookahead to restrict the character class \w: (?!Q)\w After the negative lookahead asserts that what follows the current position is...
Read more >
Lookahead and lookbehind - The Modern JavaScript Tutorial
Negative lookahead. Let's say that we want a quantity instead, not a price from the same string. That's a number \d+ , NOT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found