Jump to content
Cliff

[SOLVED] Find and Replace the Clipboard, then Paste

Recommended Posts

I want to copy something like

wp-content/plugins/event-tickets/tests/restv1/TicketNotAccessibleCest.php

and convert it to

codecept run tests/restv1/TicketNotAccessibleCest.php

and paste it

 

the "event-tickets" part is variable, which is why I used regex to match \w

 

When I run with debugging on, it's like the Clipboard (what I think should be {query}) is blank. Screenshot: https://cl.ly/120d35b1fd91

 

Is that a bug or an error in my workflow?

 

Workflow is here: https://cl.ly/005392a2a9cd

 

Thanks for helping!

Share this post


Link to post
12 hours ago, Cliff said:

When I run with debugging on, it's like the Clipboard (what I think should be {query}) is blank.

 

That’s because you’re not telling the Hotkey to use the clipboard.

32CPSeC.jpg

 

Check your connections. You have a connection that goes from the Hotkey to the Copy to Clipboard.


- in event-tickets is not a word character. A more robust option is ^wp-content/plugins/[^/]*/.

Share this post


Link to post

OMG, the simplest things... tyvm!

 

Here's some regex testing that matches what I want: https://regex101.com/r/UeGzX3/1

However, it requires escaping forward slashes yet http://userguide.icu-project.org/strings/regexp seems to not require doing so (so I didn't in my workflow)

 

Workflow that actually works now except for the regex matching - and interestingly not showing up in debugger: https://cl.ly/5acd6e68fdb1

Share this post


Link to post
Posted (edited)
2 hours ago, Cliff said:

However, it requires escaping forward slashes

 

Yeah. Not all regex engines are the same. You have to check the precise syntax for the one you're using. PCRE (Perl-compatible regular expressions) require you to escape forward slashes because they're the syntax used to indicate that something is a regular expression: "this is a string" /this is a regular expression/

 

2 hours ago, Cliff said:

Workflow that actually works now

 

It doesn't. Your Replace isn't actually connected. You're just passing the clipboard contents straight through:

 

image.png.fa901b4efc8717a7dc4cd14784820f0a.png

 

Your regex is also wrong: (\w|\-)+ means "word character OR -". Putting the plus outside the brackets also means the group only contains one character. Use the regex @vitor gave you: [^/]+, which means "as many characters as possible that aren't slashes", in a match group (because you want to extract it): ([^/]+)

 

Finally, it's a Replace utility, but you have the "with" field empty, meaning you're deleting the match, not extracting it. You need to put $1 in the "with" box ($1 means the first match group). This appears to be a working configuration:

 

image.png.0bcc19476c2d1fca91d27f99bf039643.png

 

Regular expressions are tricky. Whenever you reach for them, bear in mind the immortal words of Jamie Zawinski:

 

Quote

 Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Edited by deanishe

Share this post


Link to post

I had a different filter in the middle and I guess deleting it made it connect further down the road - or, more likely, I didn't initially connect it properly anyway. ugh - not on my game with this one

 

My regex and vitor's regex both worked, but I did appreciate your explanation of the rule - it does sound better - although the plus is better than asterisk, as demonstrated here (not matching double slash): https://regex101.com/r/wvT3FC/1

 

I didn't add the $1 as a replacement because I do want it removed

 

Thanks for the help and the tips. Really appreciate it!

Share this post


Link to post
44 minutes ago, Cliff said:

I didn't add the $1 as a replacement because I do want it removed

 

Yes, right. Sorry. I got the bits you wanted to keep mixed up in my head at some point, and wrote it to keep the bit you actually wanted to throw away…

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...