DD
DevDash

Regex for JSON Null

Regex Pattern

^null$

JSON null literal

Quick Answer

The regex pattern for json null is `^null$`. JSON null literal. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
null✓ Matches
Null✗ No match
NULL✗ No match
undefined✗ No match
nil✗ No match
None✗ No match

Code Examples

javascript

const regex = /^null$/;
const isValid = regex.test(value);

python

import re
pattern = r'^null$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^null$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^null$/', $value)) {
    echo "valid";
}

java

String pattern = "^null$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.