Raffael
Raffael

Reputation: 20045

usage of ...Pattern.compile()

Using java.util.regex.Pattern.compile() you can specify a pattern as parameter. But how can you specify flags like case-insensitive and ignore whitespaces as well?

Upvotes: 2

Views: 840

Answers (4)

Gursel Koca
Gursel Koca

Reputation: 21300

java.util.regex.Pattern.compile(String regex, int flags);

Parameters:

  • regex, the expression to be compiled flags Match
  • flags, a bit mask

You can set flags to a bitmask composed by

  • CASE_INSENSITIVE
  • MULTILINE
  • DOTALL
  • UNICODE_CASE
  • CANON_EQ
  • UNIX_LINES
  • LITERAL
  • COMMENTS

Upvotes: 3

wjans
wjans

Reputation: 10115

You can use the Pattern.compile(String regex, int flags) method that takes flags as well, or you can put them in your Pattern itself:

Eg.

Pattern.compile("(?i)a");

Upvotes: 4

Suraj Chandran
Suraj Chandran

Reputation: 24801

Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);

Upvotes: 3

Related Questions