learnbyexample

joined 2 years ago

Well, I'm not going to even try understanding the various features used in that sed command. I do know how to use basic loops with labels, but I never bothered with all the buffer manipulation stuff. I'd rather use awk/perl/python for those cases.

[–] learnbyexample@programming.dev 2 points 2 weeks ago (2 children)

This might work, but I think it is best to not tinker further if you already have a working script (especially one that you understand and can modify further if needed).

perl -pe 's/\[[^]]+\]\((?!https?)[^#]*#\K[^)]+(?=\))/lc $&=~s:%20|\d\K\.(?=\d):-:gr/ge'
[–] learnbyexample@programming.dev 1 points 3 weeks ago (1 children)

Hmm, OP mentioned "Only edit what’s between parentheses" - don't see anywhere that whole URL shouldn't be changed...

[–] learnbyexample@programming.dev 2 points 3 weeks ago* (last edited 3 weeks ago) (7 children)

Here's a solution with perl (assuming you don't want to change http/https after the start of ( instead of start of a line):

perl -pe 's/\[[^]]+\]\(\K(?!https?)[^)]+(?=\))/lc $&=~s|%20|-|gr/ge' ip.txt
  • e flag allows you to use Perl code in the substitution portion.
  • \[[^]]+\]\(\K match square brackets and use \K to mark the start of matching portion (text before that won't be part of $&)
  • (?!https?) don't match if http or https is found
  • [^)]+(?=\)) match non ) characters and assert that ) is present after those characters
  • $&=~s|%20|-|gr change %20 to - for the matching portion found, the r flag is used to return the modified string instead of change $& itself
  • lc is a function to change text to lowercase
 

Hello!

I recently published a new version of my Understanding Python re(gex)? ebook.

This book will help you learn Python Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises. In addition to the standard library re, the third-party regex module is also covered in this book.

Release offers

To celebrate the new release, you can download the PDF/EPUB versions for free till 31-Jan-2025:

Interactive TUI app

I wrote a TUI app to help you solve exercises from this book interactively. See PyRegexExercises repo for installation steps and app_guide.md for instructions on using this app.

See my blog post Python regex cheatsheet for a quick reference.

Web version and GitHub repo

You can read the book online here: https://learnbyexample.github.io/py_regular_expressions/

Visit https://github.com/learnbyexample/py_regular_expressions for markdown source, example files, exercise solutions, sample chapters and other details related to the book.

Feedback and Errata

I would highly appreciate it if you'd let me know how you felt about this book. It could be anything from a simple thank you, rating/review, pointing out a typo, mistakes in code snippets, which aspects of the book worked for you (or didn't!) and so on. Reader feedback is essential and especially so for self-published authors.

Happy learning :)

[–] learnbyexample@programming.dev 7 points 1 month ago (1 children)

Check out my chapter on GNU grep BRE/ERE for those wanting to learn this regex flavor: https://learnbyexample.github.io/learn_gnugrep_ripgrep/breere-regular-expressions.html (there's also another chapter for PCRE)

Memory, Sorrow, and Thorn by Tad Williams

[–] learnbyexample@programming.dev 4 points 2 months ago

I use Vim ;)

Python itself provides IDLE, which is good enough for beginners. https://thonny.org/ is another good one for beginners.

As mentioned by others, Jetbrains is good for many languages. https://www.kdevelop.org/ is another option.

[–] learnbyexample@programming.dev 6 points 2 months ago

I wish you success. I'm happy to use SimpleScreenRecorder(https://github.com/MaartenBaert/ssr).

[–] learnbyexample@programming.dev 1 points 6 months ago

I have a list of learning resources for CLI tools and scripting here: https://learnbyexample.github.io/curated_resources/linux_cli_scripting.html

I've also written a few TUI interactive apps to practice text processing commands like grep, sed, awk, coreutils, etc: https://github.com/learnbyexample/TUI-apps

[–] learnbyexample@programming.dev 1 points 6 months ago* (last edited 6 months ago) (2 children)

Why do you think it is a phishing link? Gumroad is a well known platform to sell digital goods.

I mention it is free up to some date because it will go back to being a paid product after that.

view more: next ›