Regular expression for the text need

Afdahfafhafha sfsfsf afsfsfklk
afdadafaf sfsfsf
afaf
afafsfgdg dgsdgsg
Have you ever been to school?
No
Have you ever been not to school?
Yes
Explain the details.

i want the output only No from the given text
format is standard.

Hi @T_Y_Raju

(?<=Have you ever been to school\?\s+)\w+

Output = System.Text.RegularExpressions.Regex.Match(Input,"(?<=Have you ever been to school\?\s+)\w+").Value.Trim()

Regards

@T_Y_Raju

System.Text.RegularExpressions.Regex.Match(Input,"No").Value

or

(?<=Have you ever been to school\?\s+).*

if there are 2 No then

@T_Y_Raju

Use find matching pattern activity
For loop to iterate
Log message

Hi @T_Y_Raju

Then Use Matches

Output = System.Text.RegularExpressions.Regex.Matches(Input,"(?<=Have you ever been to school\?\s+)\w+")

After that you can print it using below syntax in message box:

String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Regards

Hi @T_Y_Raju

Try this in assign activity:

MatchesResult= System.Text.RegularExpressions.Regex.Matchs(str_Input, "(?<=Have you ever been to school\?\s+)\w+", RegexOptions.IgnoreCase)

Datatype is
image

Hi @T_Y_Raju

Input = "Afdahfafhafha sfsfsf afsfsfklk
afdadafaf sfsfsf
afaf
afafsfgdg dgsdgsg
Have you ever been to school?
No
Have you ever been not to school?
Yes
Explain the details.
Afdahfafhafha sfsfsf afsfsfklk
afdadafaf sfsfsf
afaf
afafsfgdg dgsdgsg
Have you ever been to school?
No
Have you ever been not to school?
Yes
Explain the details.
"
Output = System.Text.RegularExpressions.Regex.Matches(Input,"(?<=Have you ever been to school\?\s+)\w+")

Output is of DataType IEnumerable(System.Text.RegularExpressions.Match)
Use below syntax to print it in message box:

String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Regards

Hi @T_Y_Raju

(?<=\?\s)No*

Hope it helps!!

@T_Y_Raju

If you already know the text you need why you need to extract

please explain what will you do…do you need which question got no answer?

cheers

i want only Have you ever been to school? below that No as output i dont want any other text below that

@T_Y_Raju

basically you need the question before no

try this

.*\r?\n(?>No)

Usage: Requiredvalue = System.Text.RegularExpressions.Regex.Match(str,".*\r?\n(?>No)",RegexOptions.MultiLine).Value

cheers

no i want only answer No and i dont want any other text

@T_Y_Raju

Then y do you need to extract also…directly just use no

Or \bNo\b

Cheers

String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

this expression is given error as Cast not a member of Match

could you please send me the expression

Hi @T_Y_Raju

What is the Output variable Datatype. It should be IEnumerable(System.Text.RegularExpressions.Match)

If possible share your flow.

Regards

Hey @T_Y_Raju
Always you can try use vb.net script like this:

Dim inputText As String = "Your string or variable"
Dim pattern As String = "(?<=Have you ever been to school\?\s?)No"
Dim regex As New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.Multiline)
Dim matches As System.Text.RegularExpressions.MatchCollection = regex.Matches(inputText)

Dim results As New System.Text.StringBuilder()

For i As Integer = 0 To matches.Count - 1
    results.AppendLine(matches(i).Value)
Next

result = results.ToString()

image

@T_Y_Raju

Try this

Requiredvalue = System.Text.RegularExpressions.Regex.Match(str,".\bNo\b",RegexOptions.MultiLine).Value

cheers