Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for Ethereum address
Regex pattern · validation

Regex for Ethereum address

Regex for Ethereum address: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^0x[a-fA-F0-9]{40}$/ as an Ethereum address regex. It matches "0x52908400098527886E0F7030069857D2E4169EE7" and "0xde709f2102306220921060314715629080e2fb77", and rejects "52908400098527886E0F7030069857D2E4169EE7" and "0x52908400098527886E0F7030069857D2E4169EE". Mixed-case addresses carry an EIP-55 checksum that regex cannot verify; use a library such as ethers.js isAddress.

Last updated · Maintained by FreeAIToolz · How we test

/^0x[a-fA-F0-9]{40}$/
  • 0x52908400098527886E0F7030069857D2E4169EE7matches
  • 0xde709f2102306220921060314715629080e2fb77matches
  • 52908400098527886E0F7030069857D2E4169EE7no match
  • 0x52908400098527886E0F7030069857D2E4169EEno match
  • 0xZZ908400098527886E0F7030069857D2E4169EE7no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
^0xhex prefix
[a-fA-F0-9]{40}$40 hex characters (20 bytes)

Examples

InputResult
0x52908400098527886E0F7030069857D2E4169EE7✓ Matches
0xde709f2102306220921060314715629080e2fb77✓ Matches
52908400098527886E0F7030069857D2E4169EE7✗ No match
0x52908400098527886E0F7030069857D2E4169EE✗ No match
0xZZ908400098527886E0F7030069857D2E4169EE7✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Mixed-case addresses carry an EIP-55 checksum that regex cannot verify; use a library such as ethers.js isAddress.

When to use this pattern

Wallet address fields before sending a transaction.

Use it in your language

JavaScript

const re = /^0x[a-fA-F0-9]{40}$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^0x[a-fA-F0-9]{40}$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^0x[a-fA-F0-9]{40}$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^0x[a-fA-F0-9]{40}$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^0x[a-fA-F0-9]{40}$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for Ethereum address?
/^0x[a-fA-F0-9]{40}$/. Mixed-case addresses carry an EIP-55 checksum that regex cannot verify; use a library such as ethers.js isAddress.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abc0x52908400098527886E0F7030069857D2E4169EE7xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.