Pattern Breakdown
Understanding the regex pattern ^\S+@\S+\.\S+$:
- ^ - Start of string
- $ - End of string
- \S - Non-whitespace character
- + - One or more
Examples
| Input | Result | Explanation |
|---|---|---|
test@test.com |
✓ Match | Basic email |
a@b.c |
✓ Match | Minimal valid email |
no spaces@email.com |
✗ No Match | Contains space |
Code Examples
JavaScript
JavaScript
const pattern = /^\S+@\S+\.\S+$/;
const text = "test@test.com";
// Test if string matches
if (pattern.test(text)) {
console.log("Valid!");
}
// Extract matches
const matches = text.match(pattern);
console.log(matches);
Python
Python
import re
pattern = r'^\S+@\S+\.\S+$'
text = "test@test.com"
# Test if string matches
if re.match(pattern, text):
print("Valid!")
# Find all matches
matches = re.findall(pattern, text)
print(matches)
PHP
PHP
<?php
$pattern = '/^\S+@\S+\.\S+$/';
$text = "test@test.com";
// Test if string matches
if (preg_match($pattern, $text)) {
echo "Valid!";
}
// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches);
?>
Java
Java
import java.util.regex.*;
String pattern = "^\\S+@\\S+\\.\\S+$";
String text = "test@test.com";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);
if (m.matches()) {
System.out.println("Valid!");
}
Use Cases
Common applications: Quick validation, client-side checks
- Form validation and input sanitization
- Data extraction and parsing
- Search and replace operations
- API request/response validation
- Log file analysis
Frequently Asked Questions
What is the regex pattern for simple email regex?
The regex pattern is: ^\S+@\S+\.\S+$. A simple email validation regex for basic checks. Less strict but catches most invalid emails.
How do I use the simple email regex pattern in JavaScript?
In JavaScript: const regex = new RegExp('^\\S+@\\S+\\.\\S+$'); or const regex = /^\S+@\S+\.\S+$/;
Does this pattern work in Python?
Yes, use: import re; pattern = re.compile(r'^\S+@\S+\.\S+$') in Python. Most regex patterns are cross-language compatible.
What are common use cases for simple email regex?
Quick validation, client-side checks
Related Regex Patterns
More Regex Tools
GetDevUtils offers a suite of developer tools including:
- Regex Tester - Test and debug regular expressions
- JSON Formatter - Format and validate JSON
- Base64 Encoder/Decoder - Encode and decode Base64
- URL Encoder/Decoder - Encode and decode URLs