Cliff Posted July 30, 2019 Share Posted July 30, 2019 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! Link to comment
vitor Posted July 31, 2019 Share Posted July 31, 2019 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. 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/[^/]*/. Link to comment
Cliff Posted July 31, 2019 Author Share Posted July 31, 2019 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 Link to comment
deanishe Posted July 31, 2019 Share Posted July 31, 2019 (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: 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: 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 July 31, 2019 by deanishe Link to comment
Cliff Posted July 31, 2019 Author Share Posted July 31, 2019 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! Link to comment
Cliff Posted July 31, 2019 Author Share Posted July 31, 2019 Published to https://github.com/cliffordp/alfred-app-workflows#development if it helps anyone else in the future Again, thanks to you people for helping! Link to comment
deanishe Posted July 31, 2019 Share Posted July 31, 2019 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… Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now