This is the first line1
This is the second line2
This is the third line3
This is the fourth line4
Identify third line 3 text and extract one line above and get output as “line2”. I may either have alphabets / numerics / alpha-numerics
Please help me with single regex pattern.
regex regex-extractor
vrdabberu
(Varunraj Dabberu)
June 11, 2024, 4:12am
2
Hi @Avinesh_Ramanathan
Please check the below attached xaml, screenshot and the regex pattern and it gives the output as per your reqirement.
System.Text.RegularExpressions.Regex.Match(Input,"(?<=\n).*").Value.Trim
Xaml:
Sequence15.xaml (9.2 KB)
Screenshot:
If you need any changes to be done please let me know.
Regards
Yoichi
(Yoichi)
June 11, 2024, 4:19am
3
Hi,
How about the following expression?
System.Text.RegularExpressions.Regex.Match(yourString,".*(?= \r?\n.*third line 3)").Value.Trim
Regards,
HI, I am trying to achieve entirely through Regex pattern …
This is the first line1
This is the second line2
This is the third line3
This is the fourth line4
I am keeping third line 3 as my keyword and want to get line 2 as my output
I tried in regex101 but didnt work
Yoichi
(Yoichi)
June 11, 2024, 6:30am
6
Sorry, the above contains extra spaces.
How about the following pattern?
.*(?=\r?\n.*third line3)
vrdabberu
(Varunraj Dabberu)
June 11, 2024, 6:33am
7
Avinesh_Ramanathan:
HI, I am trying to achieve entirely through Regex pattern …
This is the first line1
This is the second line2
This is the third line3
This is the fourth line4
I am keeping third line 3 as my keyword and want to get line 2 as my output
Hi @Avinesh_Ramanathan
try with below regex pattern and I have attached the screenshot and xaml for your reference.
regex pattern:
System.Text.RegularExpressions.Regex.Match(Input,"(.*)(?=\s+.*third line3)").Value.Trim
xaml:
Sequence15.xaml (9.2 KB)
screenshot:
Regards
vrdabberu
(Varunraj Dabberu)
June 11, 2024, 6:43am
8
Hi @Avinesh_Ramanathan
If you want only the word line2 then please use the below regex expressions and also use the below flow:
Output = System.Text.RegularExpressions.Regex.Match(Input,"(.*)(?=\s+.*third line3)").Value.Trim
FinalData = System.Text.RegularExpressions.Regex.Matches(Output,"([A-Za-z0-9]+)").Last.ToString
Xaml:
Sequence15.xaml (10.1 KB)
Screenshot:
Regards
SenzoD
(Senzo Dlomo)
June 11, 2024, 7:55am
10
Can I suggest a different approach if you would allow me,
How you approach this is very risky as the regex can have more matches than required or sometimes match nothing at all, just a small change in text can throw your expression off.
I suggest, you focus on a line and try to catch the info you want from a single line of text instead of trying to apply regex on a paragraph of text.
here is an example:
testString.Split(New String() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
Once you focus on a single line you can either substring that line or apply regex but this is now minimal risk of matching incorrectly or more than desired.
system
(system)
Closed
July 1, 2024, 4:53pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.