Dave's Brain

Browse - Programming Tips - How do I convert Perl regular expression modifiers to Java Patterns

Date: 2012dec18
Language: Perl, Java, Scala
Keywords: regex

Q.  How do I convert Perl regular expression modifiers to Java Patterns

A.

Perl -> Java /m Pattern.MULTILINE /s Pattern.DOTALL /i Pattern.CASE_INSENSITIVE /x Extend your pattern's legibility by permitting whitespace and comments. Details in /x /p Preserve the string matched such that ${^PREMATCH}, ${^MATCH}, and ${^POSTMATCH} are available for use after matching. /g Global. Depends where you use the Pattern /c Keep the Current position after failed matching. Not equivalent. /e Execute. Not directly available. You can read code that loops over matches /u Always in Unicode /a, /d, /l These modifiers, all new in 5.14, affect which character-set semantics (Unicode, etc.) are used

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.