Created
November 22, 2015 23:37
-
-
Save yannick/f17647fb2f8ff2261d42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.algorithm, std.file, std.regex; | |
import std.string; | |
import std.stdio; | |
import std.container.dlist; | |
import std.range; | |
void main() | |
{ | |
string ua = "Mozilla/5.0 (iPhone CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3"; | |
//string ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25"; | |
auto cantChangeThat = r"(iPhone)(?:;| Simulator;)?".regex(); | |
auto fmt = "mystring: $1"; | |
auto m2 = ua.matchAll(cantChangeThat); | |
auto res = ua.replaceAll(cantChangeThat, fmt); | |
assert("mystring: iPhone" == res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment