Hello Everyone,
I have actually done this by using multiple lines of code. But because I am no expert at RegEx, I thought maybe one of you might know how to do the same in just one line.
Let's say you have a string.
Let>MyString=45;23;22;45;11
Is there a pattern I can use with Regex that will return only the number or numbers that repeat.
RegEx>Pattern,MyString,0,Result,nm,0
Using the above RegEx, I would like Result_1 to be 45. Since no other numbers repeat, in this case, there would only be one result.
(The number is a variable, and can be any number.)
My macro needs to make a choice. And I want it to choose only the numbers that repeat.
Sorry. An actual example is not possible, since my macro is way to long to post.
Thanks for the assist,
PepsiHog
Need a bit of RegEx Help
Moderators: JRL, Dorian (MJT support)
Need a bit of RegEx Help
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
Just one line huh? You're not asking for much are you... 
RegEx never ceases to amaze... yes its possible... here you go:
Your line was the first one, mine was the second.
If you single step in the debugger, you'll find the following result variable created which finds the repeated value:
RESULT_1=45
Now let's add a second 11 in there and...
RESULT_1=45
RESULT_2=11
Is that what you were looking for?
The following code will let you quickly add in other multiple numbers to your string then test the results...
One caveat: if a number, let's say 45... were to appear three times in the string... you'd get 45 as a result twice.
If this is a problem for you then you could write some extra code to delete any duplicate matches or...
...it may even be possible to accomplish that within the RegEx expression itself.
If it is I'd love to see it so... open challenge... 5 rep points up for grabs.
Take care

RegEx never ceases to amaze... yes its possible... here you go:
Code: Select all
Let>MyString=45;23;22;45;11
RegEx>\b(\d+)(?=.*\b\1\b),MyString,0,Result,num_matches,0
If you single step in the debugger, you'll find the following result variable created which finds the repeated value:
RESULT_1=45
Now let's add a second 11 in there and...
Code: Select all
Let>MyString=45;23;22;45;11;11
RegEx>\b(\d+)(?=.*\b\1\b),MyString,0,Result,num_matches,0
RESULT_2=11
Is that what you were looking for?
The following code will let you quickly add in other multiple numbers to your string then test the results...
Code: Select all
Let>MyString=45;23;22;45;11;11
Let>Pattern=\b(\d+)(?=.*\b\1\b)
RegEx>Pattern,MyString,0,Result,num_matches,0
If>num_matches=0
MDL>MyString=%MyString% and contains no repeating numbers... time for a Pepsi!
Else
MDL>MyString=%MyString% contains %num_matches% repeating numbers and they are...
Let>counter=0
Repeat>counter
Let>counter=counter+1
MDL>RESULT_%counter%
Until>counter,num_matches
EndIf
If this is a problem for you then you could write some extra code to delete any duplicate matches or...
...it may even be possible to accomplish that within the RegEx expression itself.
If it is I'd love to see it so... open challenge... 5 rep points up for grabs.
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

not me...
Thanks! jpuziano!
That is exactly what I need.
Actually concerned because once I complete what I'm doing, I am hoping to share it here on the forum. It's a macro just for fun. (If I can do it!) But that's all I can say.
Thanks again!
Edit - BTW. What site do you get your info from for RegEx? The sites I go to don't seem to be that great.
That is exactly what I need.
Not a problem. Any given number can only be repeated once.One caveat: if a number, let's say 45... were to appear three times in the string... you'd get 45 as a result twice.
Nah. LOL!Just one line huh? You're not asking for much are you.
Actually concerned because once I complete what I'm doing, I am hoping to share it here on the forum. It's a macro just for fun. (If I can do it!) But that's all I can say.
Thanks again!
Edit - BTW. What site do you get your info from for RegEx? The sites I go to don't seem to be that great.
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
me
**giggle,giggle**
Thanks again!!!
I went online and, thanks to your example, I now have learned just a bit more about how to use RegEx.
PepsiHog
Thanks again!!!
I went online and, thanks to your example, I now have learned just a bit more about how to use RegEx.

PepsiHog
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!