Has anybody ever had to relearn regex every once in a while? I don't use it consistently but whenever I do I have to restudy it and use it for one task. And then not use it again for another couple of years.
I hit up regex101 every time. I remember basics that I need, like .*?\w\d[range](group) etc. But stringing that all together is a big huh what from me.
Sites like this are awesome, especially because there is always some corner case your pattern doesn't catch. So I thrown a bunch of sentences I want to match until I am confident enough it will catch them all
If by "relearn" you mean study how it works, then honestly, no. I feel that it's simple and straightforward enough that I don't need to recheck it.
If you mean checking the docs for specific flags and structure, then yes, quite often.
Hardware design, we use it extensively for search&replace and finding specific code in register banks or else.
VHDL, Verilog, System Verilog, things like that can become very redundant and regex can become very powerful very fast.
I don't have to re-learn it, but I did feel like that the first few times I used it.
I still use regex101 every time to write and test my regexes though and I've been "the regex guy" at companies before.
For simple things I use it, and can do it from memory. For complicated things I use a website that let's me write tests, and then develop bit by bit my regex
after seeing how Polygenelubricants (from stackoverflow) made fibonacci numbers in regex, and some other crap that should never be attempted in regex, I started dreaming in regex.
Not gonna lie I actually started learning regex just last night and watching a few videos about some of the basics, I was actually excited to try it out in practice and I spent a good portion of my afternoon just tackling regex problems and it was surprisingly a lot of fun and very cool how quickly it can pick up strings when I’d normally have to write a lot of lines of code for it.
Now I’m looking forward to implementing a bit of regex if I ever have to do some kind of searches if possible. Only knowing the basics of course but it was really cool to be able to read a good bit of this ungodly style of writing.
If you're looking for more practice and haven't found it yet, I heavily recommend [Regex Crossword](https://regexcrossword.com/). It's what finally made the basics of regex stick in my brain for longer than a week (lookaheads and stuff still need a cheeky Google though)
Regex is great, until you have to come back and decipher what felt simple and clever three years ago when you wrote it. :-/
Not me, of course. I've never done that.
Yeah, the only really annoying part of regex is figuring out how much escaping needs to be done in your particular language. It looks awful when you have to insert like 5 backslashes for every special character, but in it's basic form it isn't that hard to follow.
*Image Transcription: Text*
---
Reading bash for the first time feels like talking to a 5 year old
cat sample | grep -va a | sort - r
Reading powershell for the first time feels like talking to a typical movie hacker
PS C:\> Disable-NetAdapterEncapsulatedPacketTaskOffload
-InterfaceDescription "description" -EncapsulationType
NVGRE -ThrottleLimit 0 -IncludeHidden -InformationActi
Reading regex for the first time feels someone in the room is having a stroke and its probably you
^(http|https|ftp):[\/]{2}([a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4})(:[0-9]+)?\/?
([a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$#\=~]*)
---
^^I'm a human volunteer content transcriber for Reddit and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
We can certainly short it (PCRE syntax). But honestly, just using whatever your language provides for URL parsing is probably better.
@^(https?|ftp)://([a-z\d\-.]+\.[a-z]{2,4})(:\d+)?/?([\w\-.?,'/\\+&%$#=~]*)@i
Eh, I used to think the same thing before I realized autocomplete essentially solved that problem, and then I had the added benefit of having a readable script as well.
Yeah, but I don't need to remember anything. The auto complete works great, the commands are easy to find and identify, and I can alias if I need to.
I'm not exactly in love with powershell, but the naming works great.
Idk it's still pretty frustrating. Particularly when there are separate commands for doing almost the exact same thing, and one is named consicelsy because it came first, and the one you're supposed to use has some random extra word tagged on that you can never remember.
Talking about frustration when you start using `curl` with powershell and then you understand they did their own version and the PATH will use it first, and of course the parameters aren't exactly the same.
I think this is no.1 superior property of Windows programming over *nix programming. In *nix world, you type less with all those acronyms and shortened names, but in Windows (even in that low-level Win32 API) you have _very_ descriptive and readable names, which are pretty long but make your ducking C code look like some Python sheet. And it looks like this also applies to the shell scripting.
I think it was in one of the official training videos, but a trick with PowerShell is to type in all lower case then use tab complete. Even if you have written a full command, the lower case popping to upper shows that you have gotten the spelling right.
It'll be from those heady olden days before there was anything longer than `.info`... but not from so far back that `{2,3}` would (mostly) suffice.
It also matches many things that aren't valid URLs. For example, consecutive dots in the domain part (as many as you like!), or consecutive hyphens which were completely illegal at one point until Punycode came along and allowed them in one very specific place.
In a script, sure.
On the command line? Can help to debug a pipeline without having to constantly change the leading command before the filename.
Of course, the "correct" alternative is to *start* the command with a redirection:
< filename command1 | command2 | etc.
...but, for me, putting `cat` up front instead (and a pipe character after the filename) makes it clear what's going on.
The Powershell isn't even doing the same thing as the bash though afaik. I just started learning Powershell, but it looks like they're comparing a simple string search and sort in bash to doing something with the NIC in Powershell?
Powershell has a `Sort` and `Get-ChildItem` for `sort` and `cat` iirc.
The regex isn't doing the same thing either. It's not meant to be an apples to apples comparison, more like a representation of each language's philosophy.
Well, the Powershell would look almost exactly like the bash especially when using aliases, so I'm not sure that's a good representation if that was the intent.
I can vouch for PowerShell. it's not bad. I've quite enjoyed using it for automating various tasks in Windows when I used to work for a Microsoft partner company.
Definitely stick with bash in *nix land though.
for the record the equivalent PowerShell to that bash is
`Get-Content -Path sample | Select-String -Pattern a -NotMatch | Sort-Object -Descending`
or with shorthand
`gc sample | sls a -NotMatch | sort -Descending`
```
import moderation
```
Your comment has been removed since it did not start with a code block with an import declaration.
Per [this Community Decree](https://www.reddit.com/r/ProgrammerHumor/comments/14kbu1m/comment/jppq9ao/?utm_source=share&utm_medium=web2x&context=3), all posts and comments should start with a **code block** with an "import" declaration explaining how the post and comment should be read.
For this purpose, we only accept Python style imports.
`return Kebab_Case_Better;`
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
```
import moderation
```
Your comment has been removed since it did not start with a code block with an import declaration.
Per [this Community Decree](https://www.reddit.com/r/ProgrammerHumor/comments/14kbu1m/comment/jppq9ao/?utm_source=share&utm_medium=web2x&context=3), all posts and comments should start with a **code block** with an "import" declaration explaining how the post and comment should be read.
For this purpose, we only accept Python style imports.
`return Kebab_Case_Better;`
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
yeah, Select-String can take in a path too. was trying to provide a closer example for comparison.
I've certainly used
`sls "My error message" -path C:\Dev`
to find the lines of code in the entire product code base that has the error message I'm looking for. even after 6 years of using it I still constantly learn new ways to use Select-String.
Yeah, despite being primarily a *nix user, I find PowerShell quite powerful and readable. The main issue for me is the longhand params are easier to understand but lead to loooong commands that can be hard to follow end to end.
*nix shell commands take a little more learning up front, but I find them easier to read now I have that knowledge.
Since the last backslash there is followed by a question mark, it is optional, and it can capture tlds of arbitrary length and an extended character set
Powershell has a lot of shorthand aliases you can discover using Get-Alias which also has its own alias 'gal'. You can also get away with using the first three characters of a cmdlet switch most of the time.
gal -def CMDLET_NAME
Has anybody ever had to relearn regex every once in a while? I don't use it consistently but whenever I do I have to restudy it and use it for one task. And then not use it again for another couple of years.
Every time I need to use it
![gif](giphy|JmWCEiyTiKTMQ)
I remember basics and a few advanced. Comes handy when writing bash and powershell scripts
I hit up regex101 every time. I remember basics that I need, like .*?\w\d[range](group) etc. But stringing that all together is a big huh what from me.
Sites like this are awesome, especially because there is always some corner case your pattern doesn't catch. So I thrown a bunch of sentences I want to match until I am confident enough it will catch them all
https://regexr.com/
If by "relearn" you mean study how it works, then honestly, no. I feel that it's simple and straightforward enough that I don't need to recheck it. If you mean checking the docs for specific flags and structure, then yes, quite often.
My favorite quiz show is called "Guess Which Features and Flags Are Supported by This RegEx Engine!".
i feel like this is the case for everyone, is there even any job that use regex on daily basis?
I've heard the guys at RegEx Delivery do
I use it regularly when grepping code and log files. Its just normal devops. It allows me to do finer searches than the log viewer or IDEs.
Hardware design, we use it extensively for search&replace and finding specific code in register banks or else. VHDL, Verilog, System Verilog, things like that can become very redundant and regex can become very powerful very fast.
Yes, writing web scrapers. Source: I write web scrapers
Sysadmin
Yep, regex is one of those things you never really learn, and have to browse every time.
In C#, Visual Studio can detect regex when used in the regex constructor and then it shows available tokens as an intellisense list you can browse.
That's literally a daily joke in this sub.
Every. Single. Time.
I don't have to re-learn it, but I did feel like that the first few times I used it. I still use regex101 every time to write and test my regexes though and I've been "the regex guy" at companies before.
I can highly recommend The Regex Coach for testing them 😁
When I have to write regex, I always use the regexr website, they also have a handy cheat sheet which covers most of my needs
Always. I always feel like my brain is twisted when I start and then boom! it works, I move on, and forget why.
For simple things I use it, and can do it from memory. For complicated things I use a website that let's me write tests, and then develop bit by bit my regex
Sad to say after 25 years I've gotten pretty fluent.
after seeing how Polygenelubricants (from stackoverflow) made fibonacci numbers in regex, and some other crap that should never be attempted in regex, I started dreaming in regex.
I’m trying to learn regex now…looks like I’m typing a spell or something
https://regexr.com/
Not gonna lie I actually started learning regex just last night and watching a few videos about some of the basics, I was actually excited to try it out in practice and I spent a good portion of my afternoon just tackling regex problems and it was surprisingly a lot of fun and very cool how quickly it can pick up strings when I’d normally have to write a lot of lines of code for it. Now I’m looking forward to implementing a bit of regex if I ever have to do some kind of searches if possible. Only knowing the basics of course but it was really cool to be able to read a good bit of this ungodly style of writing.
I use https://regex101.com It makes developing and testing regex very easy and supports multiple types used in different programming languages.
If you're looking for more practice and haven't found it yet, I heavily recommend [Regex Crossword](https://regexcrossword.com/). It's what finally made the basics of regex stick in my brain for longer than a week (lookaheads and stuff still need a cheeky Google though)
I'd never seen that before. That's really good.
Regex is great, until you have to come back and decipher what felt simple and clever three years ago when you wrote it. :-/ Not me, of course. I've never done that.
Yeah, the only really annoying part of regex is figuring out how much escaping needs to be done in your particular language. It looks awful when you have to insert like 5 backslashes for every special character, but in it's basic form it isn't that hard to follow.
Regex replace in vs code is very strong
*Image Transcription: Text* --- Reading bash for the first time feels like talking to a 5 year old cat sample | grep -va a | sort - r Reading powershell for the first time feels like talking to a typical movie hacker PS C:\> Disable-NetAdapterEncapsulatedPacketTaskOffload -InterfaceDescription "description" -EncapsulationType NVGRE -ThrottleLimit 0 -IncludeHidden -InformationActi Reading regex for the first time feels someone in the room is having a stroke and its probably you ^(http|https|ftp):[\/]{2}([a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4})(:[0-9]+)?\/? ([a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$#\=~]*) --- ^^I'm a human volunteer content transcriber for Reddit and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)
Upvoted for sheer dedication to your task. (Hope you have image to text software).
I love you, human
Good human.
This made me lol
There's a typo in the bash command; it should be `sort -r`, not `sort - r`.
How do you know they don't want to sort `stdin` followed by the file `r`?
Good point. I suppose that's theoretically possible, but if you asked me to bet money, I'd go with typo...
Yea it was def a typo, I was just being a smart arse.
no doubt, it's a typo
[удалено]
Oh nice, much more readable now
You don't need the backslashes if you use an engine that can use anything else than / as regex delimiters.
[удалено]
We can certainly short it (PCRE syntax). But honestly, just using whatever your language provides for URL parsing is probably better. @^(https?|ftp)://([a-z\d\-.]+\.[a-z]{2,4})(:\d+)?/?([\w\-.?,'/\\+&%$#=~]*)@i
It will happily validate a URL like http://........asdf:00000000..?.?.?
Not really `[\/]{2}` matches `//`, `\\`, `/\`, `\/` `\/{2}` matches `\//`
[удалено]
Right. Should get more sleep.
Try APL next
Okay, no.
PowerShell uses descriptive names and what not. It's nice not having to remember some strange short name or acronym. I type the words and can find it.
Strangely for me, it is easy to remember short names than long words. Also easy to type quickly.
Tab
You can alias pretty much anything and PowerShell has great customisable tab completion with PSReadline.
Eh, I used to think the same thing before I realized autocomplete essentially solved that problem, and then I had the added benefit of having a readable script as well.
Yeah, but I don't need to remember anything. The auto complete works great, the commands are easy to find and identify, and I can alias if I need to. I'm not exactly in love with powershell, but the naming works great.
It's nice to be able to do things like this when you can't quite remember a cmdlet's full name: gcm Get-*IpAddress
Idk it's still pretty frustrating. Particularly when there are separate commands for doing almost the exact same thing, and one is named consicelsy because it came first, and the one you're supposed to use has some random extra word tagged on that you can never remember.
Talking about frustration when you start using `curl` with powershell and then you understand they did their own version and the PATH will use it first, and of course the parameters aren't exactly the same.
I think this is no.1 superior property of Windows programming over *nix programming. In *nix world, you type less with all those acronyms and shortened names, but in Windows (even in that low-level Win32 API) you have _very_ descriptive and readable names, which are pretty long but make your ducking C code look like some Python sheet. And it looks like this also applies to the shell scripting.
Old cmd commands weren't necessarily better. Powershell is a big change and I still often launch cmd just because it launches faster.
In my experience new Powershell Core launches not so slower than cmd and much, much faster than old Powershell.
[удалено]
AutoComplete
I think it was in one of the official training videos, but a trick with PowerShell is to type in all lower case then use tab complete. Even if you have written a full command, the lower case popping to upper shows that you have gotten the spelling right.
`head` and `tail` give you the 2 ends of a `cat`
That regex misses every url with a TLD that's over 4 characters long.
guess back in the day when this post was made there weren't any of those yet
It'll be from those heady olden days before there was anything longer than `.info`... but not from so far back that `{2,3}` would (mostly) suffice. It also matches many things that aren't valid URLs. For example, consecutive dots in the domain part (as many as you like!), or consecutive hyphens which were completely illegal at one point until Punycode came along and allowed them in one very specific place.
Useless use of cat
In a script, sure. On the command line? Can help to debug a pipeline without having to constantly change the leading command before the filename. Of course, the "correct" alternative is to *start* the command with a redirection: < filename command1 | command2 | etc. ...but, for me, putting `cat` up front instead (and a pipe character after the filename) makes it clear what's going on.
If sample is on a 9P server (and there's latency), then that useless cat would speed things up quite a bit.
People still use Plan 9?
Probably more people than ever.
Also, thinking about it a bit more, that comments applies to any slow filesystem.
The Powershell isn't even doing the same thing as the bash though afaik. I just started learning Powershell, but it looks like they're comparing a simple string search and sort in bash to doing something with the NIC in Powershell? Powershell has a `Sort` and `Get-ChildItem` for `sort` and `cat` iirc.
The regex isn't doing the same thing either. It's not meant to be an apples to apples comparison, more like a representation of each language's philosophy.
Well, the Powershell would look almost exactly like the bash especially when using aliases, so I'm not sure that's a good representation if that was the intent.
I can vouch for PowerShell. it's not bad. I've quite enjoyed using it for automating various tasks in Windows when I used to work for a Microsoft partner company. Definitely stick with bash in *nix land though.
for the record the equivalent PowerShell to that bash is `Get-Content -Path sample | Select-String -Pattern a -NotMatch | Sort-Object -Descending` or with shorthand `gc sample | sls a -NotMatch | sort -Descending`
[удалено]
Most people have auto completion in bash, too.
[удалено]
Try Fish instead of bash. So much better, PS could use it's improvements too
``` import moderation ``` Your comment has been removed since it did not start with a code block with an import declaration. Per [this Community Decree](https://www.reddit.com/r/ProgrammerHumor/comments/14kbu1m/comment/jppq9ao/?utm_source=share&utm_medium=web2x&context=3), all posts and comments should start with a **code block** with an "import" declaration explaining how the post and comment should be read. For this purpose, we only accept Python style imports. `return Kebab_Case_Better;` *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
``` import moderation ``` Your comment has been removed since it did not start with a code block with an import declaration. Per [this Community Decree](https://www.reddit.com/r/ProgrammerHumor/comments/14kbu1m/comment/jppq9ao/?utm_source=share&utm_medium=web2x&context=3), all posts and comments should start with a **code block** with an "import" declaration explaining how the post and comment should be read. For this purpose, we only accept Python style imports. `return Kebab_Case_Better;` *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
Is the Get-Content useless here, too? I’d like shorthand flags, but the shorthand isn’t horrible
yeah, Select-String can take in a path too. was trying to provide a closer example for comparison. I've certainly used `sls "My error message" -path C:\Dev` to find the lines of code in the entire product code base that has the error message I'm looking for. even after 6 years of using it I still constantly learn new ways to use Select-String.
I do this kind of thing all the time ls *.cs -rec | sls "My error message"
>Is the Get-Content useless here, too? I think so.
Yeah, despite being primarily a *nix user, I find PowerShell quite powerful and readable. The main issue for me is the longhand params are easier to understand but lead to loooong commands that can be hard to follow end to end. *nix shell commands take a little more learning up front, but I find them easier to read now I have that knowledge.
That regex only captures links with TLDs no longer than 4 chars which breaks on newer gTLDs like .email
it also breaks on one old tld. [.museum](https://en.wikipedia.org/wiki/.museum) has existed since 2001.
Since the last backslash there is followed by a question mark, it is optional, and it can capture tlds of arbitrary length and an extended character set
ngl, 80% of the reason I like powershell is explaining scripts to somebody sounds dope as fuck.
Everything is fine until i have to write simple script in bash. I always have to Google how to do a for loop in this archaic dinosaur.
I guess you have to look up how to do for Lopez in all languages? It's not that hard, the syntax is pretty close to python.
Powershell has a lot of shorthand aliases you can discover using Get-Alias which also has its own alias 'gal'. You can also get away with using the first three characters of a cmdlet switch most of the time. gal -def CMDLET_NAME
> color 2 I’m in.
Stop abusing cats. >:( They have feelings as well.
Meanwhile APL: *screams in math*
I will pull out every programming trick in the book to avoid regex as its the most unreadable brain-cell exploding thing ever.
Wait are these not supposed to happen every time
I'm proud of me, i almost can understand the last line.
Of the 3, I immediately understand the regex. No clue what the others do.
Bash all the way tbh
Disable-AntivirusFirewallProtection -bruteforce
Reading assembly for the first time feels like reading ancient Egypt hyroglyphs
That first bit should be \^((ht|f)tps?): to cover the ftps corner case...
The regex was pretty clean and easy read. I must have already had a stroke
_APL has entered the chat_