regex with literal (ie automatically replace '(' with '\(', etc) )
Timothee Cour
thelastmammoth at gmail.com
Wed May 29 16:20:15 PDT 2013
See below:
import std.stdio;
import std.regex;
void main(){
"h(i".replace!(a=>a.hit~a.hit)(regex(`h\(`,"g")).writeln; //this works, but
I need to specify the escape manually
// "h(i".replace!(a=>a.hit~a.hit)(regex(`h(`,"gl")).writeln; //I'd like
this to work with a flag, say 'l' (lowercase L) as in 'litteral'.
}
note, std.array.replace doesn't work because I want to be able to use
std.regex' replace with delegate functionality as above.
This is especially useful when the regex's first argument is given as an
input argument (ie is unknown), and we want to properly escape it.
Alternatively, (and perhaps more generally), could we have a function:
string toRegexLiteral(string){
//replace all regex special characters (like '(' ) with their escaped
equivalent
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130529/44a1c9ca/attachment-0001.html>
More information about the Digitalmars-d-learn
mailing list