SlideShare a Scribd company logo
1 of 18
Download to read offline
Regexp in Android and Java
Keishin Yokomaku @ Drivemode, Inc.
potatotips #22
@KeithYokoma
• Keishin Yokomaku at Drivemode, Inc.
• Work
• Android apps
• Android Training and its publication
• Like
• Bicycle, Photography, Tumblr and Motorsport
2
Pattern.compile()
3
Android is not Java
• Android and Java have different implementation respectively on regexp API.
• Same regexp, different result.
• Write once, not run anywhere (☆ ‿ ☆)
4
What’s the matter?
5
Test env vs. runtime
• If your tests are running on JVM(e.g. with Robolectric)…
• Some patterns pass the test, but won’t work at runtime.
• Some patterns work at runtime, but won’t pass the test.
6
 ̄_(ツ)_/ ̄
7
Differences in detail
8
Supported flags
• Java
• All flags defined at Pattern are supported.
• Android
• Only CASE_INSENSITIVE, COMMENTS, DOTALL, LITERAL,
MULTILINE, UNICODE_CASE, UNIX_LINES are supported.
• If any other flags are set, RuntimeException will be thrown.
9
Android Pattern
public class Pattern {
private Pattern(String pattern, int flags) throws PatternSyntaxException {
if ((flags & CANON_EQ) != 0) {
throw new UnsupportedOperationException(“CANON_EQ flag not supported”);
}
int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL |
LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES;
if ((flags & ~supportedFlags) != 0) {
throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags));
}
this.pattern = pattern;
this.flags = flags;
compile();
}
}
10
Android Pattern
public class Pattern {
private Pattern(String pattern, int flags) throws PatternSyntaxException {
if ((flags & CANON_EQ) != 0) {
throw new UnsupportedOperationException(“CANON_EQ flag not supported”);
}
int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL |
LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES;
if ((flags & ~supportedFlags) != 0) {
throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags));
}
this.pattern = pattern;
this.flags = flags;
compile();
}
}
11
Android Pattern
public class Pattern {
private Pattern(String pattern, int flags) throws PatternSyntaxException {
if ((flags & CANON_EQ) != 0) {
throw new UnsupportedOperationException(“CANON_EQ flag not supported”);
}
int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL |
LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES;
if ((flags & ~supportedFlags) != 0) {
throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags));
}
this.pattern = pattern;
this.flags = flags;
compile();
}
}
12
Java Pattern
public class Pattern {
private void compile() {
if (has(CANON_EQ) && !has(LITERAL)) {
normalize();
} else {
normalizedPattern = pattern;
}
patternLength = normalizedPattern.length();
// Copy pattern to int array for convenience
// Use double zero to terminate pattern
temp = new int[patternLength + 2];
hasSupplementary = false;
int c, count = 0;
// Convert all chars into code points
for (int x = 0; x < patternLength; x += Character.charCount(c)) {
c = normalizedPattern.codePointAt(x);
if (isSupplementary(c)) {
hasSupplementary = true;
}
temp[count++] = c;
}
patternLength = count; // patternLength now in code points
// ……
}
}
13
Character class
• Java
• Matches only single byte characters
• Android
• Matches both single byte and multi byte characters.
• Details here: http://bit.ly/1R73wkM
14
Regular expression engines
• Java
• java.util.regex Engine
• Conform Unicode Technical Standard #18 Level1 and Release
2.1”Canonical Equivalents”.
• Android
• ICU(International Components for Unicode) Engine
• Conform Unicode Technical Standard #18 Level 1 and Default Word
Boundaries and Name Properties from Level2
15
Canonical Equivalents
• Canonically equivalent code point sequences are assumed to have the
same appearance and meaning when printed or displayed.
• e.g. “ü” and “u¨” are canonically equivalent
16
Android is not Java
 ̄_(ツ)_/ ̄
17
Regexp in Android and Java
Keishin Yokomaku @ Drivemode, Inc.
potatotips #22

More Related Content

What's hot

Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseJeanne Boyarsky
 
Eclipse Luna - What's New!
Eclipse Luna - What's New!Eclipse Luna - What's New!
Eclipse Luna - What's New!Noopur Gupta
 
Trainmesofttech - Selenium Training In Hyderabad 
Trainmesofttech - Selenium Training In Hyderabad Trainmesofttech - Selenium Training In Hyderabad 
Trainmesofttech - Selenium Training In Hyderabad Trainmesofttech
 
Robolectric android taipei
Robolectric   android taipeiRobolectric   android taipei
Robolectric android taipeiRichard Chang
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java TutorialJava2Blog
 
Eclipse Tips & Tricks - EclipseCon North America 2014
Eclipse Tips & Tricks - EclipseCon North America 2014Eclipse Tips & Tricks - EclipseCon North America 2014
Eclipse Tips & Tricks - EclipseCon North America 2014Noopur Gupta
 
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...Iosif Itkin
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Noopur Gupta
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework IntroductionPekka Klärck
 
Java 8 tooling in Eclipse
Java 8 tooling in EclipseJava 8 tooling in Eclipse
Java 8 tooling in EclipseNoopur Gupta
 
Java Comments | Java course
Java Comments | Java courseJava Comments | Java course
Java Comments | Java courseRAKESH P
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014Noopur Gupta
 

What's hot (20)

Diving into Java Class Loader
Diving into Java Class LoaderDiving into Java Class Loader
Diving into Java Class Loader
 
Java introduction
Java introductionJava introduction
Java introduction
 
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
 
Eclipse Luna - What's New!
Eclipse Luna - What's New!Eclipse Luna - What's New!
Eclipse Luna - What's New!
 
Trainmesofttech - Selenium Training In Hyderabad 
Trainmesofttech - Selenium Training In Hyderabad Trainmesofttech - Selenium Training In Hyderabad 
Trainmesofttech - Selenium Training In Hyderabad 
 
Robolectric android taipei
Robolectric   android taipeiRobolectric   android taipei
Robolectric android taipei
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Eclipse Tips & Tricks - EclipseCon North America 2014
Eclipse Tips & Tricks - EclipseCon North America 2014Eclipse Tips & Tricks - EclipseCon North America 2014
Eclipse Tips & Tricks - EclipseCon North America 2014
 
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
TMPA-2015: The Application of Parameterized Hierarchy Templates for Automated...
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Java 8 tooling in Eclipse
Java 8 tooling in EclipseJava 8 tooling in Eclipse
Java 8 tooling in Eclipse
 
Java Comments | Java course
Java Comments | Java courseJava Comments | Java course
Java Comments | Java course
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
Spock pres
Spock presSpock pres
Spock pres
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 

Similar to Differences in Regex Support Between Android and Java

DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaHenri Tremblay
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practicesAlessio Ricco
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfKALAISELVI P
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James NelsonGWTcon
 
OOP with Java
OOP with JavaOOP with Java
OOP with JavaOmegaHub
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongGrokking VN
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongVu Huy
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017Ayush Sharma
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)Shaharyar khan
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectŁukasz Dumiszewski
 

Similar to Differences in Regex Support Between Android and Java (20)

Android Dev Study Jam.pptx
Android Dev Study Jam.pptxAndroid Dev Study Jam.pptx
Android Dev Study Jam.pptx
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
 
Android Dev Study Jam.pptx
Android Dev Study Jam.pptxAndroid Dev Study Jam.pptx
Android Dev Study Jam.pptx
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Make it compatible
Make it compatibleMake it compatible
Make it compatible
 
Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Introduction
IntroductionIntroduction
Introduction
 
Java vs .Net
Java vs .NetJava vs .Net
Java vs .Net
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire project
 

More from Keishin Yokomaku

More from Keishin Yokomaku (13)

UI optimization for night
UI optimization for nightUI optimization for night
UI optimization for night
 
Popup view on Mortar
Popup view on MortarPopup view on Mortar
Popup view on Mortar
 
Deep Inside Android Hacks
Deep Inside Android HacksDeep Inside Android Hacks
Deep Inside Android Hacks
 
Signature
SignatureSignature
Signature
 
Android Media Hacks
Android Media HacksAndroid Media Hacks
Android Media Hacks
 
Null, the Abyss
Null, the AbyssNull, the Abyss
Null, the Abyss
 
?
??
?
 
Building stable and flexible libraries
Building stable and flexible librariesBuilding stable and flexible libraries
Building stable and flexible libraries
 
Typeface
TypefaceTypeface
Typeface
 
Version Management
Version ManagementVersion Management
Version Management
 
イカしたライブラリを作った話
イカしたライブラリを作った話イカしたライブラリを作った話
イカしたライブラリを作った話
 
Google I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と GradleGoogle I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と Gradle
 
自己組織化
自己組織化自己組織化
自己組織化
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Differences in Regex Support Between Android and Java

  • 1. Regexp in Android and Java Keishin Yokomaku @ Drivemode, Inc. potatotips #22
  • 2. @KeithYokoma • Keishin Yokomaku at Drivemode, Inc. • Work • Android apps • Android Training and its publication • Like • Bicycle, Photography, Tumblr and Motorsport 2
  • 4. Android is not Java • Android and Java have different implementation respectively on regexp API. • Same regexp, different result. • Write once, not run anywhere (☆ ‿ ☆) 4
  • 6. Test env vs. runtime • If your tests are running on JVM(e.g. with Robolectric)… • Some patterns pass the test, but won’t work at runtime. • Some patterns work at runtime, but won’t pass the test. 6
  • 9. Supported flags • Java • All flags defined at Pattern are supported. • Android • Only CASE_INSENSITIVE, COMMENTS, DOTALL, LITERAL, MULTILINE, UNICODE_CASE, UNIX_LINES are supported. • If any other flags are set, RuntimeException will be thrown. 9
  • 10. Android Pattern public class Pattern { private Pattern(String pattern, int flags) throws PatternSyntaxException { if ((flags & CANON_EQ) != 0) { throw new UnsupportedOperationException(“CANON_EQ flag not supported”); } int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL | LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES; if ((flags & ~supportedFlags) != 0) { throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags)); } this.pattern = pattern; this.flags = flags; compile(); } } 10
  • 11. Android Pattern public class Pattern { private Pattern(String pattern, int flags) throws PatternSyntaxException { if ((flags & CANON_EQ) != 0) { throw new UnsupportedOperationException(“CANON_EQ flag not supported”); } int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL | LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES; if ((flags & ~supportedFlags) != 0) { throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags)); } this.pattern = pattern; this.flags = flags; compile(); } } 11
  • 12. Android Pattern public class Pattern { private Pattern(String pattern, int flags) throws PatternSyntaxException { if ((flags & CANON_EQ) != 0) { throw new UnsupportedOperationException(“CANON_EQ flag not supported”); } int supportedFlags = CASE_INSENSITIVE | COMMENTS | DOTALL | LITERAL | MULTILINE | UNICODE_CASE | UNIX_LINES; if ((flags & ~supportedFlags) != 0) { throw new IllegalArgumentException(“Unsupported flags: “ + (flags & ~supportedFlags)); } this.pattern = pattern; this.flags = flags; compile(); } } 12
  • 13. Java Pattern public class Pattern { private void compile() { if (has(CANON_EQ) && !has(LITERAL)) { normalize(); } else { normalizedPattern = pattern; } patternLength = normalizedPattern.length(); // Copy pattern to int array for convenience // Use double zero to terminate pattern temp = new int[patternLength + 2]; hasSupplementary = false; int c, count = 0; // Convert all chars into code points for (int x = 0; x < patternLength; x += Character.charCount(c)) { c = normalizedPattern.codePointAt(x); if (isSupplementary(c)) { hasSupplementary = true; } temp[count++] = c; } patternLength = count; // patternLength now in code points // …… } } 13
  • 14. Character class • Java • Matches only single byte characters • Android • Matches both single byte and multi byte characters. • Details here: http://bit.ly/1R73wkM 14
  • 15. Regular expression engines • Java • java.util.regex Engine • Conform Unicode Technical Standard #18 Level1 and Release 2.1”Canonical Equivalents”. • Android • ICU(International Components for Unicode) Engine • Conform Unicode Technical Standard #18 Level 1 and Default Word Boundaries and Name Properties from Level2 15
  • 16. Canonical Equivalents • Canonically equivalent code point sequences are assumed to have the same appearance and meaning when printed or displayed. • e.g. “ü” and “u¨” are canonically equivalent 16
  • 17. Android is not Java  ̄_(ツ)_/ ̄ 17
  • 18. Regexp in Android and Java Keishin Yokomaku @ Drivemode, Inc. potatotips #22