Have you tried simple RegEx? It generally works very fast.
Here's an example with 57 lines that runs very fast.
Try it with you 2400 line array. Just change the RegEx to Search a file instead of a variable.
Example Output
MACRO: Extract Number from Text Given Keyword [Example] @Regex
#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/f/7/f773438b36b1a89c3f06d6be9c61b37ac60f28d2.kmmacros">Extract Number from Text Given Keyword [Example] @Regex.kmmacros</a> (8.8 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
### ReleaseNotes
Author.@JMichaelTX
**PURPOSE:**
* **Extract Number for given Keyword**
**NOTICE: This macro/script is just an _Example_**
* It is provided only for _educational purposes_, and may not be suitable for any specific purpose.
* It has had very limited testing.
* You need to test further before using in a production environment.
* It does not have extensive error checking/handling.
* It may not be complete. It is provided as an example to show you one approach to solving a problem.
**REQUIRES:**
1. **KM 8.0.2+**
* But it can be written in KM 7.3.1+
* It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
.
2. **macOS 10.11.6 (El Capitan)**
* KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:
**MACRO SETUP**
* **Carefully review the Release Notes and the Macro Actions**
* Make sure you understand what the Macro will do.
* You are responsible for running the Macro, not me. 😉
.
* Assign a Trigger to this maro.
* Move this macro to a Macro Group that is only Active when you need this Macro.
* ENABLE this Macro.
.
* **REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:**
* ALL Actions that are shown in the magenta color
**USE AT YOUR OWN RISK**
* While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
* **Ask first**
* Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.
---

---
### Let us know if this works for you, or you have questions?
That's why I love this community!
Thanks a lot @JMichaelTX. That was insanely fast.
Right now I am just searching from Variable array. Is there any advantage to using a Txt file instead of Variable?
I mean I am pretty impressed with the speed already. It's insanely fast!
Certainly. As one possible way to do this, we can tweak @JMichaelTX's example macro to use the For Each action to collect each matching keyword number into one results variable:
To use this macro with a text file instead of a variable (either should work fine, but I imagine it would be more convenient to use a text file if that's what the array is already in) just change this option in the For Each action:
Gabe, I didn't notice until after my above post, but you also changed my RegEx pattern:
Mine is: (?mi)^%Variable%Local__KeyWord%,(\d+)
The key difference is that mine requires that the keyword start at the beginning of the line. I haven't tested yours, but I believe it could yield a false positive if the keyword was partially contained in another line, as in:
123456,12
456,9
I believe your RegEx would find the first line for a keyword of "456".
I'll leave it up to you to test and confirm/refute my assertion.