@ovi
Need help in getting text before the string. please see the below text
D I A Plnt SLoc Targ. Qty Un Net Price Curr. per Un
4700101201 ZCV 1000005566 AMPHENOL MALAYSIA SDN BHD CI8 09/15/1998
Agreement Start09/15/1998 Agreement End 12/31/9999
L 0 PC 8.89 USD 1 PC
4700102285 ZCV 1000006987 AMPHENOL ASSEMBLETECH B48 04/06/2020
Agreement Start04/06/2020 Agreement End 12/31/9999
in the above text I need number before “ZCV”. and ZCV will be present in single/multiple times. So I need to collect all strings just before the “ZCV”
exmple output will strarry ZCV = 4700101201, 4700102285, etc…
Assign a variable of type MatchCollection
to System.Text.RegularExpressions.Regex.Matches(MyStr, ".+(?=ZCV)")
to get the collection of all matches of strings preceeding ZCV. If you don’t want the space after the number, use System.Text.RegularExpressions.Regex.Matches(MyStr, ".+(?=\sZCV)")
.
3 Likes
One more help needed @Anthony_Humphries
In below text there is an L just below the #4700101201 and #4700102489 so here i need only the id # which does not have L below to that. So here there is no L for the id# 4700102285. can you pls help me how to get the ID which does not have L below to it. and the text always not in structured format.
4700101201 ZCV 1000005566 AMPHENOL MALAYSIA SDN BHD CI8 09/15/1998
L 0 PC 8.89 USD 1 PC
4700102285 ZCV 1000006987 AMPHENOL ASSEMBLETECH B48 04/06/2020
1 PC 8.89 USD 1 PC
4700102489 ZCV 1000006987 AMPHENOL ASSEMBLETECH B48 04/06/2020
L 1 PC 8.89 USD 1 PC
It’s possible, but will be more complicated. You can create another match collection IdMatchColl
set to System.Text.RegularExpressions.Regex(MyStr, ".+(?=\sUSD)")
, and iterate over it using a For Each loop.
In the loop, create an If condition with MyMatch.Value.SubString(0, 1) <> "L"
, where MyMatch
is a single match in the loop. If the condition is true, the value you want will be in your first match collection NumMatchColl
as NumMatchColl(RowIx).Value
, where RowIx
is an Int32 variable assigned as the index in the For Each loop.
Here is one more example of text
4700101201 ZCV 1000005566 AMPHENOL MALAYSIA SDN BHD CI8 09/15/1998
Tgt Value 1,000,000.00 USD Open 0.00 USD 0.00 %
03230 960254 ACCESSRYKT AXXCBL450CVCR 0350
L 0 PC 8.89 USD 1 PC
4700102285 ZCV 1000006987 AMPHENOL ASSEMBLETECH B48 04/06/2020
Agreement Start04/06/2020 Agreement End 12/31/9999
Tgt Value 10,000,000,000.00 USD Open 9,999,999,111.00 USD 100.00 %
In the above text I need 4700102285 since there is no L below or after the ID#4700102285
There’s no L after 4700101201 either, but if you don’t want that value, you’ll need more specifics on what you’re looking for.
Sorry there was an L after 4700101201. I missed it to mention while copying text
Can you help me in this I am not able to use this in if condition I have item of mathcollections in for each.