Substracting Substring for a String

Hello, I have a long string of characters. I would like to extract a unknown string folowing a Known string.
////////////////////////////////////////////////// String
Phone Number: xxx xxx xxx
Contract Nu: 3471/207/sE
PPN B (da/ne*): Yes
//////////////////////////////////////////
Known string is “Contract Nu:”

So the result that I want would be “3471/207/sE”

Hi @tomaz,

If there are new lines in your string, you could try the following in an assign:

BigString.Split({"Contract Nu:"},StringSplitOptions.None).Last.Split({"System.Environment.NewLine"},StringSplitOptions.None).First.Trim

Hi!

You can achieve that by using the Regular Expression (RegEx)

System.Text.RegularExpressions.RegEx.Matches(Input_String,“(?<=Contract Nu:).*\n(?=PPN))”)

Regards,
NaNi

1 Like

Thank you but I am looking for more rubast solution, because sometimes strings are not seperated with newline

1 Like

You can use Regex also as an alternative

System.Text.RegularExpressions.RegEx.Match(Stringvar,“(?<=Contract Nu:\s)(\S+)”)

Matches-> Will return enumerable values
Match → Will return String Value

You can use this expression or @THIRU_NANI 's expression

Regards
Sudharsan

1 Like

Hi. What if some files are in this form


Can I do something to catch both examples?

Hi!

Regards,
NaNi

HI @tomaz

Try this one

System.Text.RegularExpressions.RegEx.Match(Stringvar,“(?<=Contract Nu:\s)(\S+)|(?<=Contract Nu:\s\n)(\S+)”)

If in case in future if you have a different form you just add the regex by adding “|” and your new pattern

Regards
Sudharsan

1 Like

Hello, thank you for your help. I have one more problem that I don’t know how to solve.
It’s basicley the same problem as before, but I need string folowing PPN B (da/ne*):
This is either DA or NE
I Know that / and * are special characters and and i try to fix that by using
but I don’t know why it doesen’t work.

Hello,
Can’t you simply do (DA|NE) ?

You have just missed \ before the paranthesis

Check this expression

Regards
Sudharsan

Thank you very much

1 Like

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