pub fn regex_from_str(
json: &str,
whitespace_pattern: Option<&str>,
) -> Result<String>
Expand description
Generates a regular expression string from given JSON schema string.
ยงExample
use outlines_core::prelude::*;
// Define a JSON schema
let schema = r#"{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"]
}"#;
// Generate regex from schema
let regex = json_schema::regex_from_str(&schema, None)?;
println!("Generated regex: {}", regex);
// Custom whitespace pattern could be passed as well
let whitespace_pattern = Some(r#"[\n ]*"#);
let regex = json_schema::regex_from_str(&schema, whitespace_pattern)?;
println!("Generated regex with custom whitespace pattern: {}", regex);
}