I have a string
str = "ABC
abc@123
123456
DEF
def@345
345678"
Using regular expression I have to extract data and write it in a datatable with the given format
Name,uniqueID, phnumber
abc,abc@123,123456
DEF,def@234,345678
I have a string
str = "ABC
abc@123
123456
DEF
def@345
345678"
Using regular expression I have to extract data and write it in a datatable with the given format
Name,uniqueID, phnumber
abc,abc@123,123456
DEF,def@234,345678
Hi @Sachin_P
Please refer the below workflow
Input:
Input = "ABC
abc@123
123456
DEF
def@345
345678"
matches activity regex : "([A-Z][\s\S]*?\d+\s*\d+)"
Assign activity:
name = System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"([A-Z]+(?=\s*.*\d+\s*\d+))").Value.Trim()
uniqueid = System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"((?<=[A-Z]+\s*).*\d+(?=\s*\d+))").Value.Trim()
phnumber = System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"((?<=[A-Z]+\s*.*\d+\s+)(\d+))").Value.Trim()
Workflow:
Xaml:
Main.xaml (14.9 KB)
Output:
Hi,
Another approach:
mc = System.Text.RegularExpressions.Regex.Matches(str,"(?<Name>[^\r\n@]+)\r?\n(?<uniqueID>[^@\r\n]+@[^@\r\n]+)\r?\n(?<phnumber>[^@\r\n]+)(\r?\n|$)")
Then
dt = mc.Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) dt.LoadDataRow(dt.Columns.Cast(Of DataColumn).Select(Function(dc) m.Groups(dc.ColumnName).Value).ToArray(),False)).CopyToDataTable()
Sample
Sample20231228-1q.zip (3.2 KB)
Regards,
The string looks like this
"
2220
ABCD98888
Count7
2220
ABCDABCD612
Count1
2123
ABCD1234
Count1
2220
ABCD1234
Count1
123
ABCD7896
Count1
2220
ABCD7896
Count1"
output should be
Code,UniqueID,Count
2220,ABCD7896,1
123,ABCD7896,1
and so on
I tried to Tweek the sample that you gave and failed to do it for the above example, Can you help me with this sample data
Check the below workflow:
Input = "2220
ABCD98888
Count7
2220
ABCDABCD612
Count1
2123
ABCD1234
Count1
2220
ABCD1234
Count1
123
ABCD7896
Count1
2220
ABCD7896
Count1"
matches activity regex : "\d+[\s\S]*?Count\d+"
Assign activity:
Code= System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"\d+").Value.Trim()
uniqueid = System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"(?<=\d+\s*)[A-Z]+[0-9]+").Value.Trim()
Count= System.Text.RegularExpressions.Regex.Match(currentItem.ToString,"(?<=(?<=\d+\s*)[A-Z]+[0-9]+\s*[A-Za-z]+)[0-9]+").Value.Trim()
Workflow:
Will help you in case of any difficulties.
Regards,
Working fine.
Have another scenario
str
"
1
5551
85%
2
258
100%
3
896
59%
4
213
10%
"
Op
ranking,route,percentage
1,555,85
2,258,100
and so on
Help me out
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.