Extract web link and password from string

how can i extract web link and password from string? I need copy this kind of string and extract web link and password very often:

Link:https://pan.baidu.com/s/1aKsPhvckPRB2RGheB9KW5g Password:vvbd

If I can extract link and password,so i can set process to open the link and auto paste password when the link is open.

Thanks.

For this source string

Link:https://pan.baidu.com/s/1aKsPhvckPRB2RGheB9KW5g Password:vvbd

you can use for example this RegEx:

Link:\h*(\S+)\h+Password:\h*(\S+)

This allows

  • One or more horizontal spaces after Link:
  • One or more horizontal spaces after Password:

This requires

  • One or more horizontal spaces before Password:

This does not allow

  • Any whitespace inside the link itself
  • Any whitespace inside the password itself

regex101 snippet


As KM macro:

RegEx for weblink and password <2086 200305T144918>-pty-fs8
RegEx for weblink and password <2086 200305T144918>.kmmacros (2.9 KB)

2 Likes

Tom, I think you mean "Zero or more...", since you have \h*

Thanks Tom, Its works.
But I find that they are in different line it will not work.
Is there a place to learn KM RegEx expression method?


@Tom may have a better idea, but this seems to work for both cases:
Link:\h*(\S+)\s+Password:\h*(\S+)

For those interested in learning RegEx, here is my change:

  • CHG \h+Password TO \s+Password
    • the \s includes all whitespace, including new line characters, so it will match the case when the password is on the next line.

Getting Started with Regular Expressions

Regular expressions (RegEx or RegExp) are extremely powerful, but have an initial steep learning curve that is often intimidating. But once you get over that initial hump, and you continue to write new RegExp, it will become much easier.

I do all of my RegEx development at this free website:

You may also find these sites helpful:

Thanks, its very helpful!

Isn’t it correct English what I said?

The sample text has no spaces but the RegEx allows 1 or more spaces. (= requires zero or more spaces)

I would have done it the same way for the new sample text :+1:

@som:

For your future RegEx questions, always try to post the possible input text as complete as possible:

Link:https://pan.baidu.com/s/1aKsPhvckPRB2RGheB9KW5g Password:vvbd
Link:https://pan.baidu.com/s/1aKsPhvckPRB2RGheB9KW5g 
Password:vvbd

In this case it is trivial, but it already makes a difference as you have seen. In other cases the correct RegEx may be completely different if you don’t give all the information.

Also try to format the sample text as code block, as shown above.

--> Using Markdown in the Keyboard Maestro Forum [Keyboard Maestro Wiki]

This makes it clear what belongs to the sample text, and helps avoiding copy-paste errors.

1 Like

3 posts were merged into an existing topic: Clear Writing