`
love~ruby+rails
  • 浏览: 849310 次
  • 性别: Icon_minigender_1
  • 来自: lanzhou
社区版块
存档分类
最新评论

How to use regular expression in Java

阅读更多

This tip shows the way to validate a string with respect to a regular expression. java.util.regex package is used for regular expression related operations.

In this example the input string (inputStr) is validated with the regular expression (rgString).

<!-- start source code -->
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularExpExp {
    
    public static void main(String[] args) {
        
        String rgString = "write your regulat expression here";
        CharSequence inputStr = "write your input string that need to be validated";
        Pattern pattern = Pattern.compile(rgString);
        Matcher matcher = null;
        matcher = pattern.matcher(inputStr);
        
        if (matcher.matches()) {
            System.out.println("Matched");
        else {
            System.out.println("Not Matched");
        }
    }
}
分享到:
评论

相关推荐

    Jeffrey E. F. Friedl - Mastering.Regular.Expressions.3rd.Edition

    Mastering Regular Expressions, Third Edition, now includes a full chapter devoted to PHP and its powerful and expressive suite of regular expression functions, in addition to enhanced PHP coverage in ...

    UE(官方下载)

    How to use TaskMatch Environments in UltraEdit and UEStudio Configure FTP backup Save a local copy of your files when you transfer them to FTP directories Encrypt and Decrypt Text Files Use UltraEdit ...

    C++ Standard Library Quick Reference

    In recent years, the C++11 and C++14 standards have added even more efficient container classes, a new powerful regular expression library, and a portable multithreading library featuring threads, ...

    sed-awk-2nd-edition.chm

    Because all three programs use UNIX regular expressions, an entire chapter is devoted to understanding UNIX regular expression syntax. Next, the book describes how to write sed scripts. After getting...

    JavaScript Regular Expressions(PACKT,2015)

    Regular expressions are patterns or templates that allow you to define a set of rules in a natural yet vague way, giving you the ability to match and validate text. Therefore, they have been ...

    sed_awk.chm

    Chapter 9, Functions, describes how to use awk's built-in functions as well as how to write user-defined functions. Chapter 10, The Bottom Drawer, covers a set of miscellaneous awk topics. It ...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    handling capabilities, and the use of assertions to validate the expected behavior of code. &lt;br&gt;Chapter 13Strings and Regular Expressionsdescribes the built-in language and runtime support for ...

    Swing Hacks

    This chapter will show you how to do regular expression searching, dot completion, backward text, and even three different ways to give your application the bright sheen of anti-aliasing. Chapter ...

    android lint performance probe帮助.zip

    expression to the @MethodPattern annotation in LintDetectorStats.java, you might see a line like this. Conversely, it's a good sign if you see a line like this. If you make code changes to the tool, ...

    Practical Data Wrangling

    Make effective use of regular expression in the data wrangling process. Explore the tools and packages available for preparing numerical data for analysis. Learn how to have better control over the ...

    Advanced Apple Debugging & Reverse Engineering v0.9.5

    You’ve learned how to create breakpoints, how to print and modify values, as well as how to execute code while paused in the debugger. But so far you’ve been left high and dry on how to move around ...

    LINQ中文学习资料和LINQ 随身参考手册

    SQL and Regular Expression programmers alike will want to use regularly long after they’ve read the book.” -Chris Sells, Connected Systems Program Manager, Microsoft  About the Author  Joseph ...

    practical vim

    Run the same command on a selection of lines, or a set of files., Discover the “very magic” switch, which makes Vim’s regular expression syntax more like Perl’s. Build complex patterns by ...

    Practical Vim: Edit Text at the Speed of Thought

    Discover the "very magic" switch, which makes Vim's regular expression syntax more like Perl's. Build complex patterns by iterating on your search history. Search inside multiple files, then run Vim's...

    Beginning PHP 5.3

    - **User-Defined Functions:** Description of how to create and use custom functions in PHP. - **Function Parameters:** Explanation of function parameters, including default values, passing by ...

    11g_plsql_user_guide_and_reference.pdf

    #### Enhancements to Regular Expression Built-In SQL Functions In Oracle 11g Release 1, the regular expression built-in SQL functions have been significantly enhanced. These enhancements allow ...

    JavaScript 圣经第5版-Javascript编程宝典--黄金版 .rar

    Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java ...

Global site tag (gtag.js) - Google Analytics