Python Forum
Regexp that won't match anything
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regexp that won't match anything
#1
Is there a regexp that can't match any string that you throw at it, including the empty string?

(no, this isn't an attempt at nerd sniping, this is for tests).
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#2
$a
??
Reply
#3
Google? What is this? :)
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
Use a negative lookahead to make sure something isn't there... and then check if that thing is actually there?  That way, it's impossible for the check to ever match.
>>> import re
>>> regex = re.compile(r"^(?!spam)spam")
>>> regex.match("")
>>> regex.match("spam")
>>> regex.match("eggs")
>>> regex.match("s")
>>> regex.match("m")
>>> regex.match("pam")
Start-of-line character included so the regex engine doesn't scan the entire line.  If it matters :p
Reply
#5
Quote:Google? What is this? :)

Very interesting results.

also search $a by itself
one result: https://www.prairiehome.org/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check for funny characters with a regexp bertilow 4 2,711 Jan-19-2020, 10:16 AM
Last Post: bertilow
  RegExp: returning 2nd loop in new document syoung 5 3,821 May-02-2018, 12:36 PM
Last Post: syoung

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020