Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationString EvaluatorsCriteria EvaluationCustom String EvaluatorEmbedding DistanceExact MatchRegex MatchScoring EvaluatorString DistanceComparison EvaluatorsTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationString EvaluatorsRegex MatchOn this pageRegex MatchTo evaluate chain or runnable string predictions against a custom regex, you can use the regex_match evaluator.from langchain.evaluation import RegexMatchStringEvaluatorevaluator = RegexMatchStringEvaluator()Alternatively via the loader:from langchain.evaluation import load_evaluatorevaluator = load_evaluator("regex_match")# Check for the presence of a YYYY-MM-DD string.evaluator.evaluate_strings(    prediction="The delivery will be made on 2024-01-05",    reference=".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*")    {'score': 1}# Check for the presence of a MM-DD-YYYY string.evaluator.evaluate_strings(    prediction="The delivery will be made on 2024-01-05",    reference=".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*")    {'score': 0}# Check for the presence of a MM-DD-YYYY string.evaluator.evaluate_strings(    prediction="The delivery will be made on 01-05-2024",    reference=".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*")    {'score': 1}Match against multiple patterns‚ÄãTo match against multiple patterns, use a regex union "|".# Check for the presence of a MM-DD-YYYY string or YYYY-MM-DDevaluator.evaluate_strings(    prediction="The delivery will be made on 01-05-2024",    reference="|".join([".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*", ".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*"]))    {'score': 1}Configure the
Open In Colab
Open In Colab ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationString EvaluatorsCriteria EvaluationCustom String EvaluatorEmbedding DistanceExact MatchRegex MatchScoring EvaluatorString DistanceComparison EvaluatorsTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationString EvaluatorsRegex MatchOn this pageRegex MatchTo evaluate chain or runnable string predictions against a custom regex, you can use the regex_match evaluator.from langchain.evaluation import RegexMatchStringEvaluatorevaluator = RegexMatchStringEvaluator()Alternatively via the loader:from langchain.evaluation import load_evaluatorevaluator = load_evaluator("regex_match")# Check for the presence of a YYYY-MM-DD string.evaluator.evaluate_strings(    prediction="The delivery will be made on 2024-01-05",    reference=".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*")    {'score': 1}# Check for the presence of a MM-DD-YYYY string.evaluator.evaluate_strings(    prediction="The delivery will be made on 2024-01-05",    reference=".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*")    {'score': 0}# Check for the presence of a MM-DD-YYYY string.evaluator.evaluate_strings(    prediction="The delivery will be made on 01-05-2024",    reference=".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*")    {'score': 1}Match against multiple patterns‚ÄãTo match against multiple patterns, use a regex union "|".# Check for the presence of a MM-DD-YYYY string or YYYY-MM-DDevaluator.evaluate_strings(    prediction="The delivery will be made on 01-05-2024",    reference="|".join([".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*", ".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*"]))    {'score': 1}Configure the