Regular expressions - Strings

Hi, I have a string where i have to select the string which is preceeded with zero. If there is no string preceeded with zero , then it should return null value?
i have attached the sample input and expected output.
sampletext.txt (398 Bytes)

Hi @Lalitha_Selvaraj

You can use the below regex expression:

(^0.*)

Regards

1 Like

Hi @vrdabberu . I have mentioned the expected output. pls verify.

1 Like

Hi @Lalitha_Selvaraj

Try this

0\s?[A-Za-z(\-)?]+

Regards,

Hi @Lalitha_Selvaraj

Check the below flow:
Sequence.xaml (10.9 KB)

Regards

Hi @lchirathapudi. Its Working, but if there is No zero preceded it should return “null” or empty value.

Let me check @vrdabberu.

Can you please send the screenshot of .xaml. I’m not able to access.

Hi @Lalitha_Selvaraj

FLOW:

=> Read Text File
Output → str_Text

=> Use below syntax in Assign:

Assign -> Line_Matches = System.Text.RegularExpressions.Regex.Matches(str_Text,".*[A-Za-z0-9 ]+.*") 

Line_Matches is of DataType IEnumerable(System.Text.RegularExpressions.Match)

=> Use For Each loop to iterate through Line_Matches

For Each currentMatch in Line_Matches
    Assign -> RequiredOutput = If(System.Text.RegularExpressions.Regex.IsMatch(currentMatch.ToString.Trim,"0\s*[A-Za-z0-9- ]+"),System.Text.RegularExpressions.Regex.Match(currentMatch.ToString.Trim,"(?<=0\s*)[A-Za-z0-9- ]+").Value.Trim,"")

    Use Add Item to Collections activity and pass `RequiredOutput`
End For Each

=> Use below syntax to print it in Message Box:

String.Join(Environment.NewLine, Output_List)

Regards

1 Like

@Lalitha_Selvaraj

It should return null or empty value if no zero preceded. let me know if it solves your query.

Thanks,
Pallavi

1 Like

Hi @Lalitha_Selvaraj

Have your query resolved?

Regards

1 Like

Working with this Pattern:
grafik

strText = yourInput
strPattern = (?<=\b0).+?\

Assign Activity
arrResults | StringArray =

System.Text.RegularExpressions.Regex.Matches(strText, strPattern).Cast(of Match).Select(Function (x) x.Value.Trim).toArray

Empty case:

And can detect founds / no founds with arrResults .Any()

UPD1 - Visualizations

To detect the no match (no 0) line you need to split the input text into separate lines and use Regex.Match for each line.

For example:

outputText = 
String.Join(vbNewLine, inputText.Split(vbCrLf.ToCharArray, StringSplitOptions.RemoveEmptyEntries).Select(Function(l) System.Text.RegularExpressions.Regex.Match(l, "(?<=\b0 ?)[\w-]+")).Select(Function(m, i) (i+1) & ". " & If (m.Success, m.Value, "-")))

Hi @ptrobot . Its working fine. Thanks.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.