Skip to content

Instantly share code, notes, and snippets.

@yannick
Created November 22, 2015 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannick/f17647fb2f8ff2261d42 to your computer and use it in GitHub Desktop.
Save yannick/f17647fb2f8ff2261d42 to your computer and use it in GitHub Desktop.
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