// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r#"(?sx)#PostgreSQL v10+
(?<delimiter>; [;\s]*) #semicolon, followed by semicolons and spaces
| '(?>[^']+|'')*' #String Constants
| \b[Ee]'(?>[^\\']+|''|\\.)*' #String Constants With C-Style Escapes
| (?<stringDollarTag>\$[a-zA-Z\d_]*\$) #Dollar-Quoted String
[^$]*+ #speed improves
.*?
\k<stringDollarTag>
| "(?>[^"]+|"")*"
| #singe-line comment
(?<singeLineComment>-- [^\r\n]*+)
| #multi-line comment
(?<MutilineComment>
/\*
[^*/]*+
(?> [^*/]++
| \*[^/]
| /[^*]
| (?&MutilineComment)
)*+
\*/
)"#).unwrap();
let string = "CREATE UNIQUE INDEX/*CONCUR-
RENTLY;*/IF NOT EXISTS custom_query_group_name_name_uindex
ON public.custom_query_group_name (lower(name)); ;
;
--CREATE INDEX /*CONCURRENTLY;*/ IF NOT EXISTS custom_query_group_name_name_trigram_index ON public.custom_query_group_name USING GIN (lower(name) gin_trgm_ops);
;
;
;
CREATE INDEX /*CONCURRENTLY*/ IF NOT EXISTS v3_company_name_trigram_index ON public.v3_company USING GIN (lower(name) gin_trgm_ops);
;
-- PostgreSQL
$function$
BEGIN
RETURN ($1 ~ $q$[\\t\\r\\n\\v\\\\]$q$);
END;
$function$;
-- PostgreSQL
SELECT $$Жанна д'Арк$$, $SomeTag$Жанна д'Арк$SomeTag$;
SELECT 'abc\\''\\\\def', \"abc\\\"\"\\\\def\";
SELECT 123;
";
let substitution = "$0";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/