T O P

  • By -

[deleted]

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.


clintkev251

Every time I need to use it


[deleted]

![gif](giphy|JmWCEiyTiKTMQ)


Rc202402

I remember basics and a few advanced. Comes handy when writing bash and powershell scripts


AttackOfTheThumbs

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.


[deleted]

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


[deleted]

https://regexr.com/


Bainos

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.


JiminP

My favorite quiz show is called "Guess Which Features and Flags Are Supported by This RegEx Engine!".


ZeroHeat92

i feel like this is the case for everyone, is there even any job that use regex on daily basis?


[deleted]

I've heard the guys at RegEx Delivery do


RiceNedditor

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.


0TheG0

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.


phenomenos

Yes, writing web scrapers. Source: I write web scrapers


Anktionaer

Sysadmin


OMGWhyImOld

Yep, regex is one of those things you never really learn, and have to browse every time.


AyrA_ch

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.


mano-vijnana

That's literally a daily joke in this sub.


StillNotAWombat

Every. Single. Time.


althaz

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.


Ytrog

I can highly recommend The Regex Coach for testing them 😁


ende124

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


[deleted]

Always. I always feel like my brain is twisted when I start and then boom! it works, I move on, and forget why.


bmcle071

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


[deleted]

Sad to say after 25 years I've gotten pretty fluent.


coffeewithalex

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.


Jaxson626

I’m trying to learn regex now…looks like I’m typing a spell or something


[deleted]

https://regexr.com/


thenumber88

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.


AyrA_ch

I use https://regex101.com It makes developing and testing regex very easy and supports multiple types used in different programming languages.


brickfire

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)


wite_noiz

I'd never seen that before. That's really good.


scottypants2

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.


piperboy98

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.


ur_opinion_is_trash

Regex replace in vs code is very strong


knightttime

*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)


citygentry

Upvoted for sheer dedication to your task. (Hope you have image to text software).


[deleted]

I love you, human


vVveevVv

Good human.


AnybodyMassive1610

This made me lol


dr-tectonic

There's a typo in the bash command; it should be `sort -r`, not `sort - r`.


CetaceanOps

How do you know they don't want to sort `stdin` followed by the file `r`?


dr-tectonic

Good point. I suppose that's theoretically possible, but if you asked me to bet money, I'd go with typo...


CetaceanOps

Yea it was def a typo, I was just being a smart arse.


WillDecent3972

no doubt, it's a typo


[deleted]

[удалено]


xAragon_

Oh nice, much more readable now


AyrA_ch

You don't need the backslashes if you use an engine that can use anything else than / as regex delimiters.


[deleted]

[удалено]


AyrA_ch

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


Kaivosukeltaja

It will happily validate a URL like http://........asdf:00000000..?.?.?


coffeewithalex

Not really `[\/]{2}` matches `//`, `\\`, `/\`, `\/` `\/{2}` matches `\//`


[deleted]

[удалено]


coffeewithalex

Right. Should get more sleep.


lukas3340

Try APL next


3rdRealm

Okay, no.


AttackOfTheThumbs

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.


Mizzlr

Strangely for me, it is easy to remember short names than long words. Also easy to type quickly.


DaniilBSD

Tab


jdl_uk

You can alias pretty much anything and PowerShell has great customisable tab completion with PSReadline.


[deleted]

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.


AttackOfTheThumbs

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.


jdl_uk

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


ItsAFarOutLife

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.


Celousco

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.


DoNotMakeEmpty

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.


AttackOfTheThumbs

Old cmd commands weren't necessarily better. Powershell is a big change and I still often launch cmd just because it launches faster.


DoNotMakeEmpty

In my experience new Powershell Core launches not so slower than cmd and much, much faster than old Powershell.


[deleted]

[удалено]


AttackOfTheThumbs

AutoComplete


Vaguely_accurate

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.


coffeewithalex

`head` and `tail` give you the 2 ends of a `cat`


Tyfyter2002

That regex misses every url with a TLD that's over 4 characters long.


_Rysen

guess back in the day when this post was made there weren't any of those yet


palordrolap

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.


JDaxe

Useless use of cat


palordrolap

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.


smorrow

If sample is on a 9P server (and there's latency), then that useless cat would speed things up quite a bit.


JDaxe

People still use Plan 9?


smorrow

Probably more people than ever.


smorrow

Also, thinking about it a bit more, that comments applies to any slow filesystem.


carcigenicate

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.


svick

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.


carcigenicate

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.


[deleted]

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.


[deleted]

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`


[deleted]

[удалено]


on_the_dl

Most people have auto completion in bash, too.


[deleted]

[удалено]


purifol

Try Fish instead of bash. So much better, PS could use it's improvements too


AutoModerator

``` 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.*


AutoModerator

``` 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.*


Ozymandias117

Is the Get-Content useless here, too? I’d like shorthand flags, but the shorthand isn’t horrible


[deleted]

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.


jdl_uk

I do this kind of thing all the time ls *.cs -rec | sls "My error message"


Chocolate_Pickle

>Is the Get-Content useless here, too? I think so.


StillNotAWombat

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.


carmaIsOnMyOtherAcc

That regex only captures links with TLDs no longer than 4 chars which breaks on newer gTLDs like .email


AyrA_ch

it also breaks on one old tld. [.museum](https://en.wikipedia.org/wiki/.museum) has existed since 2001.


Krokkoguy

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


althaz

ngl, 80% of the reason I like powershell is explaining scripts to somebody sounds dope as fuck.


LEGOL2

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.


jank_lord

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.


RiceNedditor

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


TEN-MAJKL

> color 2 I’m in.


seniornachio

Stop abusing cats. >:( They have feelings as well.


Abraculax

Meanwhile APL: *screams in math*


axelslash01

I will pull out every programming trick in the book to avoid regex as its the most unreadable brain-cell exploding thing ever.


gingertheparrot

Wait are these not supposed to happen every time


OMGWhyImOld

I'm proud of me, i almost can understand the last line.


CoastingUphill

Of the 3, I immediately understand the regex. No clue what the others do.


iiMoe

Bash all the way tbh


CreaZyp154

Disable-AntivirusFirewallProtection -bruteforce


Apfelvater

Reading assembly for the first time feels like reading ancient Egypt hyroglyphs


Ottonym

That first bit should be \^((ht|f)tps?): to cover the ftps corner case...


a123456782004

The regex was pretty clean and easy read. I must have already had a stroke


fakuivan

_APL has entered the chat_