- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to match a line not containing a word in Java Regex
Example
import java.util.regex.Matcher; import java.util.regex.Pattern; public class NoRegTest { public static void main(String[] args) { String s="^fun"; Pattern pattern = Pattern.compile(s); Matcher matcher = pattern.matcher("Java is fun"); if(!matcher.find()) { System.out.println("not found"); } } }
Output
not found
- Related Articles
- How to match a non-word character using Java RegEx?
- How to match word characters using Java RegEx?
- How to match word boundaries using Java RegEx?
- How to match non-word boundaries using Java RegEx?
- Regex to match lines containing multiple strings in Java
- How to match end of a particular string/line using Java RegEx
- How to match beginning of a particular string/line using Java RegEx
- Match specific word in regex in JavaScript?
- Java Regular Expression to match a line that doesn't contain a word.
- How to match a range of characters using Java regex
- How to match a white space equivalent using Java RegEx?
- How not to match a character after repetition in Python Regex?\n\n
- Match all occurrences of a regex in Java
- How to match a fixed set of characters using Java RegEx
- How to match a non-white space equivalent using Java RegEx?

Advertisements