|
Antlr.
|
# ? May 24, 2017 15:27 |
|
|
# ? Jun 3, 2024 21:11 |
|
Thermopyle posted:I always use https://regex101.com/ when building regexes. Anyone have anything else they like to use more? I've got a project coming up where I need to build a lot of regexes to parse some HTML and I'm not looking forward to it. I also have https://www.debuggex.com/ bookmarked, but I think their features overlap somewhat.
|
# ? May 24, 2017 16:10 |
|
Thermopyle posted:I've got a project coming up where I need to build a lot of regexes to parse some HTML and I'm not looking forward to it. Shouldn't you use an HTML parser to parse HTML? Parsing HTML is a solved problem. Maybe you need regexes to extract a specific portion of some element once the HTML has been parsed, but you shouldn't be doing the parsing itself with regexes.
|
# ? May 24, 2017 16:28 |
|
TooMuchAbstraction posted:Shouldn't you use an HTML parser to parse HTML? Parsing HTML is a solved problem. Maybe you need regexes to extract a specific portion of some element once the HTML has been parsed, but you shouldn't be doing the parsing itself with regexes. good idea!
|
# ? May 24, 2017 17:55 |
|
Thermopyle posted:I always use https://regex101.com/ when building regexes.
|
# ? May 24, 2017 18:57 |
|
Thermopyle posted:I always use https://regex101.com/ when building regexes. Anyone have anything else they like to use more? I've got a project coming up where I need to build a lot of regexes to parse some HTML and I'm not looking forward to it. Jesus Christ you gave me a small heart attack for a moment there.
|
# ? May 24, 2017 18:58 |
|
Thermopyle posted:good idea! I assume you've seen https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 yes?
|
# ? May 24, 2017 18:58 |
|
feedmegin posted:I assume you've seen https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 yes? TooMuchAbstraction posted:Shouldn't you use an HTML parser to parse HTML? Parsing HTML is a solved problem. Maybe you need regexes to extract a specific portion of some element once the HTML has been parsed, but you shouldn't be doing the parsing itself with regexes. did you both miss this part Thermopyle posted:haha, not parsing H͓͔̏̀͆̂̎ͪ̂ͤŤ̵̷̖̟̖̜̝̜̔̓ͣ̓̒M̄̈́ͦͪ̃̆͑̑̀͏͏̙̗͈̬͔̩͙L̨͔̥̦͓̰̔̍̓̋ͬ̋́̓͝ͅ
|
# ? May 24, 2017 19:07 |
|
I have a regex question. I need to make a bunch of changes to many different bits of code that take this form:code:
and replace them with this: code:
I tried using regex to find-and-replace this all at once, but I can't get the syntax down right. I want to capture all of those 'this-string-differs-on-each-line' strings and wrap them in the {data: } stuff. I can't even select anything. How do I write this? code:
|
# ? May 24, 2017 19:20 |
|
Pollyanna posted:How do I write this? In vim it'd be something like code:
|
# ? May 24, 2017 19:24 |
|
Pollyanna posted:I have a regex question. I need to make a bunch of changes to many different bits of code that take this form: code:
Parenthesis create a capture group numbered in order from 1 that you can reference with a \# in the replace, unless you make it a non-capturing group with ?:. Also the group 0 is the whole match, but I rarely find that useful. .*? is a non-greedy (or maybe backtracking?) match all, so it won't consume the rest of the candidate tokens - just the ones it can without matching on the next token in the expression, which is a single-quote in your example. Munkeymon fucked around with this message at 19:58 on May 24, 2017 |
# ? May 24, 2017 19:47 |
|
You guys are lifesavers.
|
# ? May 24, 2017 19:58 |
|
No Safe Word posted:did you both miss this part I always thought that skipping a few lines and making the text small was just a semi-funny joke because who would that actually trap?
|
# ? May 24, 2017 20:00 |
|
Thermopyle posted:I always use https://regex101.com/ when building regexes. Anyone have anything else they like to use more? Yes, actually. Well, partially. I use regex101 for writing them, but when I'm trying to debug or see what an existing one does quickly, or just want to see the end result of one I've written to check if it's what I actually wanted, I use http://regexper.com For example, on a basic phone number parsing regex I just found online (don't ever do that, please,)
|
# ? May 24, 2017 23:17 |
|
is there any programming language that allows for run time event chain hooking, object instance mutation, reflection traversing brains and linkers, etc?
|
# ? May 25, 2017 03:25 |
|
a dangerous thot posted:is there any programming language that allows for run time event chain hooking, object instance mutation, reflection traversing brains and linkers, etc? Any dynamically-typed language that gives you decent access to the object "magic" allows for this kind of thing. Python for example lets you add/remove fields from objects by accessing the __dict__ field of the object. If you want a strongly-typed language that lets you do that kind of thing, you're probably in for a lot more pain. Reflection is a lot more unpleasant when the compiler starts having opinions about what you're doing.
|
# ? May 25, 2017 03:40 |
|
.
a dangerous thot fucked around with this message at 07:41 on Jul 27, 2018 |
# ? May 25, 2017 04:01 |
|
I'm afraid you're using domain-specific language that I don't recognize. What problem are you trying to solve, anyway?
|
# ? May 25, 2017 04:05 |
|
TooMuchAbstraction posted:I'm afraid you're using domain-specific language that I don't recognize. What problem are you trying to solve, anyway? Come on man, you're better than this.
|
# ? May 25, 2017 04:08 |
|
.
a dangerous thot fucked around with this message at 07:41 on Jul 27, 2018 |
# ? May 25, 2017 04:17 |
|
I'm sure that if you recite just a few more out-of-context buzzwords, someone will appear and give you the magical answer to solve your problem with no effort on your part. Do you actually have a problem you're trying to solve?
|
# ? May 25, 2017 04:24 |
|
Jabor posted:I'm sure that if you recite just a few more out-of-context buzzwords, someone will appear and give you the magical answer to solve your problem with no effort on your part. is that a roundabout way to say it doesnt exist and i should make it because im definitely asking its existence
|
# ? May 25, 2017 04:26 |
|
No-one knows what you're asking for because your description of what you want is mostly just a bag of meaningless words that doesn't actually do anything to describe what it is you're looking for. Do you have a problem you're trying to solve?
|
# ? May 25, 2017 04:31 |
|
a dangerous thot posted:is that a roundabout way to say it doesnt exist and i should make it because im definitely asking its existence I think this is what you're looking for?
|
# ? May 25, 2017 04:31 |
|
.
a dangerous thot fucked around with this message at 07:40 on Jul 27, 2018 |
# ? May 25, 2017 04:46 |
|
That's a solution. What's the problem you're trying to solve?
|
# ? May 25, 2017 05:05 |
|
ultrafilter posted:That's a solution. What's the problem you're trying to solve?
|
# ? May 25, 2017 05:36 |
|
ultrafilter posted:That's a solution. What's the problem you're trying to solve? unnecessary work
|
# ? May 25, 2017 05:40 |
|
.
a dangerous thot fucked around with this message at 07:40 on Jul 27, 2018 |
# ? May 25, 2017 05:51 |
|
It sounds like you're trying to insert or modify code in an object oriented application while it's running. Yes? No? Am I close?
|
# ? May 25, 2017 06:08 |
|
You guys are all so loving stupid.
|
# ? May 25, 2017 06:09 |
|
.
a dangerous thot fucked around with this message at 07:39 on Jul 27, 2018 |
# ? May 25, 2017 06:14 |
|
.
a dangerous thot fucked around with this message at 07:39 on Jul 27, 2018 |
# ? May 25, 2017 06:29 |
|
I think you want Smalltalk. The virtual machine, not just the language.
|
# ? May 25, 2017 06:38 |
|
.
a dangerous thot fucked around with this message at 07:39 on Jul 27, 2018 |
# ? May 25, 2017 07:41 |
|
Check out http://joearms.github.io/2013/11/21/My-favorite-erlang-program.html
|
# ? May 25, 2017 08:28 |
|
.
a dangerous thot fucked around with this message at 07:39 on Jul 27, 2018 |
# ? May 25, 2017 08:52 |
|
So I'm learning Python 3, and I'm new to coding in general. I'm trying to make a program to sort votes for preferential counting, but I'm having some trouble working with the data I have. Sorry if my question doesn't make much sense: I have two files - one with candidate names, and a file with a series of ballots/votes in the format 1, 2, 3, 4, 5 (the preferences could be in any order) per line. My intention was to read through each ballot then apply votes to the candidates by performing rounds of vote counting. For example: in the first round I scan the ballot for "1" - if "1" is in index 0 of the string, the candidate in index 0 gets a vote. This happens for all ballots until the first round is finished, then happens again for round 2 (except it scans the ballots for "2" being the second preference), and again for however many rounds it takes to determine a clear winner. Currently each ballot is a separate string in a single list i.e ['13452', '42531', etc]. To track total votes, I have a dictionary which contains the names of each candidate and the votes they have received during the count, e.g voteTotal = {candidate[0] : 0, candidate[1] : 0 , etc : etc} The trouble I'm having is scanning each ballot string for the required preference, depending on round - I can't figure out how to scan through more than one ballot at a time. Is there a way to update the dictionary by scanning through every ballot string in the list? Here's what I tried for j in ballot: if "1" in ballot[ : ][ : ]: voteTotal.update((x, candidate) for x, candidate in voteTotal.items()) #I'm really unsure about this last line. I just read it about it in a stackoverflow question and it seemed relevant to what I needed. When I try to do the above with something like if "1" in ballot[0], it does find "1" in the first string, but it doesn't change the dictionary. With what I understand so far about indexing and slicing, I thought ballot[ : ][ : ] would enable me to scan through every index of every string in the list, but it just evaluates false for every entry. So, my question: what are some ways to scan through a large number of list indexes for specific items in each string? Currently the code doesn't give me an error, it just doesn't seem to change anything and I don't know why. TheMostFrench fucked around with this message at 12:30 on May 25, 2017 |
# ? May 25, 2017 12:28 |
TheMostFrench posted:So I'm learning Python 3 In my opinion, you are asking the wrong question. The correct question is question is, 'how do I get each voter's preferred candidate in a given round?' Also, you're using the wrong syntax to update a dictionary. The easiest and best way to update a dictionary is like this: IN Python code:
Python code:
Here's a solution of your problem. Python code:
I'm using a lot of special python syntax here for cleanliness, so there might be things here you don't understand. If there's anything you don't get ask us about it in the thread and we'll either explain it to you or give you the right terms so you can look it up yourself. Eela6 fucked around with this message at 18:57 on May 25, 2017 |
|
# ? May 25, 2017 18:41 |
|
|
# ? Jun 3, 2024 21:11 |
|
I had to look up some things like Yield, which seem interesting. I get an error at this line: loser = min(votes, key=votes.get()) code:
|
# ? May 26, 2017 09:15 |