Delete After Comma (Including the Comma – (For the RegEx Folks)!

%MacIPAddress% returns my IP address twice! I only want it once....
10.0.2.777, 10.0.2.777 why does it do that?
All I'm needing is 10.0.2.777
I know I could limit it to a number of digits with substring, but if the IP is a different number of digits it will not work.
So I think the 'firmest' solution would be regex, I googled a bit but couldn't get the definitive answer.
Appreciate any help.

For me, %MacIPAddress% works as it should, with just one copy of the address, but while you sort out why your response is different, this'll fix it:

1 Like

Hey Troy,

It does not for me – could you be doing this somewhere in your macro?

What version of macOS?
What version of Keyboard Maestro?

-Chris

Hey @ccstone hope you are well....
hmm, think it's something else attached? to the cpu, although I don't know what....
and I was not clear, when I run the %MacIPAddress%
I get
10.0.2.103,10.0.2.203

so 103 and 203, don't know!
I did do a work around though....

Ah, so... You have multiple IP Addresses.

If you just need the first one you can get by with this pattern:

,.*

-Chris

1 Like

Chris, it may not be clear to many how to use this RegEx pattern.
So, here it is:

Use the Search and Replace action

SEARCH the Variable or Clipboard with the multiple IP addresses
10.0.2.103,10.0.2.203

FOR:
,.*

REPLACE WITH:
nothing (leave it blank)

2 Likes

You probably have both WiFi and ethernet enabled. My token actually returns three addresses (I have a VPN as well.)

2 Likes