Subscribe to this thread
Home - General / All posts - SQL function to select the item of a group from regexp expression
lionel

998 post(s)
#08-May-24 20:13

i use a regexpression that cut each part of the sentences into many groups .

in https://regexr.com web UI i use

sentences : """12 M. Roger (Mathieu), maladies infectieuses et tropicales au Hopital de Nice."""

regexp : """[0-9]*)\s(M[.me]*)\s(.*)\\((.*)\\),(.*)aux*(.*)\sd['|e][La]*(.*)\\."""

i have this result ( without to take care of space in the beginning or in the end )

Is there a way with a manifold SQL function that accept a number ( 1 to 7 here) for returning a string that is one of the text content of a selected group ?

regard's

String SQL Functions (manifold.net)

StringRegexpReplaceNth(<string>, <regexp>, <target>, <occurrence|group item list ?>, <flags>) : <string>

Attachments:
regexp.png


Book about Science , cosmological model , Interstellar travels

Boyle surface fr ,en

lionel

998 post(s)
#08-May-24 20:33

C#

 void Main()

 {

 string text="12 M. Roger (Mathieu), maladies infectieuses et tropicales au Hopital de Nice.";

 string pat = @"([0-9]*)\s(M[.me]*)\s(.*)\((.*)\),(.*)aux*(.*)\sd['|e][La]*(.*)\."; // Regular expression pattern

 // Instantiate the regular expression object

 Regex r = new Regex(pat, RegexOptions.IgnoreCase);

 // Match the regular expression pattern against a text string

 Match m = r.Match(text);

 while (m.Success)

 {

 // Loop through each match and display the groups

 for (int i = 1; i < m.Groups.Count; i++)

 {

 Group g = m.Groups[i];

 Console.WriteLine($"Group{i}='{g}'");

 }

 m = m.NextMatch();

 }

 }

return using linqPad 5 program mode ( after convert \\to \)  this  : 

Group1='12'

Group2='M.'

Group3='Roger '

Group4='Mathieu'

Group5=' maladies infectieuses et tropicales '

Group6=' Hopital'

Group7=' Nice'

perhaps i have to convert the C# code to a function inside a dll to make it work/Call from manifold SQL editor ? 

Attachments:
rexp_linqpad5.png


Book about Science , cosmological model , Interstellar travels

Boyle surface fr ,en

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.