Posts by hkotsubo • 55,826 points
1,422 posts
-
3
votes1
answer42
viewsA: Get value 3 lines after given word
In your regex you have placed the "OTHER INFORMATION" section after the number, but as the number you want is after, then you must invert and put "OTHER INFORMATION" before: OUTRAS…
-
2
votes4
answers568
viewsA: Write in a file numbers separated by a certain character
The print, by default, writes to sys.stdout (which in turn will display the message in the terminal where you are running Python). That is, it does not write to the file (unless you indicate, for…
-
1
votes3
answers480
viewsA: Pick the date range separately by weeks of the current month
By your examples, you only want the days from Monday to Friday of the current month. So, you can take advantage of the relative formats to iterate through the dates: $data = new DateTime('first day…
-
1
votes2
answers312
viewsA: Regex catch value between two words
I don’t know if it was a problem copying and pasting, but after "TOTAL" has some spaces, and before the number has a >. If that’s it, just put \n will not help. An alternative is to use:…
-
3
votes1
answer297
viewsA: Regular Expression for a binary string that accepts even number of zeros
No, the string doesn’t necessarily have to start with 1. After all, 1* that is to say "zero or more occurrences of 1". The quantifier * admits zero occurrences, which means that the 1 is not…
-
1
votes2
answers120
viewsA: Capture time range in UNIX
To another answer already explained the problems of your code, but there is a catch: if the code runs on the 1st of any month, you will mount a string corresponding to the zero day, and make a…
-
5
votes4
answers200
viewsA: Find character succeeded by another character using Regex
It’s possible, I just don’t know if it’s worth it. Depending on how varied your data is, making a regex that covers all cases can get too complicated. The ideal is to correct the data at source, so…
-
3
votes2
answers3780
viewsA: How to get the index value of a list in Python?
On your list there is a value 69, but I believe you meant 699. And after the 799, place 899 (for before I was 699). It is possible to go through a list and access at the same time the index and its…
-
7
votes6
answers1947
viewsA: Use switch to test if a value is between a range of values
When you do: switch(valor) { case outroValor: .... The idea is that valor be compared with outroValor. But case outroValor is an expression, the outworking of this expression which is compared with…
-
5
votes2
answers1240
viewsA: Recursion to Python List Inversion
Just remembering that recursion is not the best way to invert a list, and throughout the answer we will understand the reasons. The basic idea of recursion is you solve a problem by solving smaller…
-
2
votes1
answer305
viewsA: How to identify if the certificate is A1 or A3?
The ICP-Brazil certificates have the extension Certificate Policies, as stated in the IRS document (see section 1.2.4): the policyIdentifier field contains the Certification Policy OID (PC) that AC…
-
3
votes3
answers134
viewsA: Starting in Python
As it begins, the first tip is use better names for variables. For example, var18 is a too generic name, which says nothing about the same, maybe pontos or pontuacao be better. Since you are saving…
-
3
votes1
answer107
viewsA: Operator problem not in the condition of a while loop
The problem is in this if: if sessão != "1" or sessão != "2": The condition or means that if any of the options is valid, it if. So if you type "2", the condition sessão != "1" is valid and he…
-
2
votes2
answers154
viewsA: Repeat loop while user choose option to continue
First, there’s no need to create two Scanner's, since both are reading from System.in. Using just one is enough (and calling one of them obj doesn’t help much, give better names for variables).…
-
4
votes1
answer79
viewsA: Get from a list all indices whose element is equal to a certain value
You don’t need to create a dictionary to save the indexes. Just go through the list with enumerate, that you can get the index and its element at the same time: def procuras(lista, valor): indices =…
-
4
votes3
answers1422
viewsA: Search for words that contain a certain letter
Taking into account that your variable text contains the excerpt "A letra z sozinha nao sera retornado na busca.", I’m assuming that’s what you need. So one way to do it is to use alternation: the…
-
4
votes1
answer72
viewsA: Select desired value with REGEX for two different standards
Your regex fails because you only check the cases in which there are : after hostname. But you also need to check if you have a -: import re textos = [ 'INSTANCE-hostname:Sys',…
-
5
votes3
answers211
viewsA: Sum of Total Positive and Negative Hours
What happens is that you are confusing "times" with "durations". To better understand, consider the two sentences below: the movie starts at two o'clock in the afternoon the film lasts two hours In…
-
5
votes2
answers489
viewsA: Recursive algorithm to check if an element belongs to a list
I understand it’s an exercise and they require the algorithm to be recursive, but for cases like this, recursion is not the best solution, because it’s an unnecessary complication. The operator in…
-
2
votes1
answer293
viewsA: Scan an Arraylist of objects and check an attribute of an object passed as parameter with an Arraylist
Your loop Scroll through the user list and see if their email matches the email of the user you want to register. As the list starts empty, there is no user, so it doesn’t even enter the for, and so…
-
16
votes4
answers7984
viewsA: How to solve 3-hour accretion problem in Date attribute in Angular?
The "Z" at the end of 2019-10-18T11:23:27.756Z indicates that this date and time is in UTC. Already when printing the Date, notice that he possesses GMT-0300, indicating 3 hours behind UTC. That is,…
-
2
votes3
answers724
viewsA: Ignore the first line of a file
You can even record all the lines in the file in an array, as said in this answer. But remember that in this case the array will have all the contents of the file loaded in memory. In the case of…
-
6
votes1
answer2963
viewsA: How to get the original branch?
This is a translation/adaptation of the answers of this question by Soen, following the recommendations of the Help Center on the translation of content into Portuguese. The commits of Git form a…
-
0
votes1
answer80
viewsA: Function to check combobox and select an appropriate Regexp
The last console.log does not print anything because the function changebancos is not being called. If you want her to be called every time select is changed, use onchange="changebancos()", and not…
-
4
votes1
answer244
viewsA: Reading JSON returns empty
The returned JSON is invalid. It has multiple "loose" objects, one followed by the other: {"date":"","env":"" ... }{"date":"","env":"", ... } Note that after the first object is closed with },…
-
4
votes2
answers1354
viewsA: Swap lyrics of a Python phrase
Python, string are immutable, so if you try to do this: s = 'abc' s[0] = 'x' The result will be a TypeError (as in fact happened with his second attempt). In this case, the way is to create another…
-
4
votes1
answer114
viewsA: How to transform string into Date object with Typescript?
You can change the function to: textoParaData(texto) { let m = texto.match(/^(\d{2})\/(\d{2})\/(\d{4})$/); if (! m) throw new Error('Deve estar no formato dd/mm/aaaa'); m = m.slice(1, 4).map(v =>…
-
0
votes2
answers249
viewsA: Date in Javascript with October 31st
In the Date of Javascript, the months are indexed at zero (January is zero, February is 1, etc). So new Date('2019','10','01') creates a date for 1 November 2019. When setting the day to 31, the…
-
0
votes2
answers1000
viewsA: Fill in a matrix and add up your numbers
An alternative to summing the values of the matrix is to use the Enhanced for (which some call "foreach"): int matriz[][] = new int[10][10]; ... // assumindo que a matriz já está com os valores…
-
4
votes1
answer157
viewsA: Problem with toFixed and decimals
First, some details on your function reading the note. First you do: let valor = parseFloat(prompt('Digite a nota do aluno')) That is to say, valor will be a number (because that’s what parseFloat…
javascriptanswered hkotsubo 55,826 -
4
votes2
answers708
viewsA: Transform into strings numbers containing semicolons
According to the documentation, parseFloat considers that the point is the decimal separator. Therefore, it is not enough to remove the comma, as the second number becomes 2.41567, which is…
javascriptanswered hkotsubo 55,826 -
4
votes2
answers1157
viewsA: Print the open range between two numbers in descending order
If you want to iterate from one number to another (not including these numbers), make a loop simple: a = 10 b = 5 while a > b + 1: a -= 1 print(a) See here the code running The while continues…
-
1
votes2
answers84
viewsA: Convert string.match() result to string?
How did you use the flag g, the method match returns an array containing all parts found (except capture groups, but since your regex doesn’t have that, then okay). So at the bottom, it all comes…
-
0
votes1
answer157
viewsA: Catch multiple occurrences of an expression in parentheses
If you need to evaluate whichever possible type of equation, regex is not the best solution. I would recommend using some parser task-specific, as we will see below, regex is quite limited to this…
-
4
votes2
answers89
viewsA: Rearview Metacharacter x does not take the corresponding groups when I change the order of these
When some part of the regex is in parentheses, it forms a catch group. Groups are numbered according to the order in which they appear in the expression. That is, in this regex: (lenta)(mente) We…
-
15
votes1
answer250
viewsA: Difference between the greedy ?? and *quantifiers?
Short answer For the regex you used, it makes no difference. But there are cases where you do. Long answer Before we remember what these are quantifiers. The ? means "zero or an occurrence", which…
-
0
votes2
answers745
viewsA: Remove characters from the middle of a String
The problem is that you calculate the size of String only at the beginning, before the while. But after the first iteration, the String will have one character less, and then you will try to catch a…
-
3
votes3
answers321
viewsA: Function to calculate the distance between two points
The calculation is not being done in the right way: Math.pow(x2, 2) - Math.pow(x1, 2); Math.pow(x2, 2) calculates x2 squared, so actually you’re doing x2² - x1². But what you want is (x2 - x1)²,…
javascriptanswered hkotsubo 55,826 -
2
votes2
answers125
viewsA: Exit loop For when typing note 1
From the various comments, hints that you want to interrupt this loop when typed 1: for (int i=0;i<possiveis.length;i++) { System.out.println("Digite as notas disponiveis"); possiveis[i] =…
-
6
votes2
answers1134
viewsA: How to get an Observable from an array item?
The idea is to use operations pipe and map, to map the answer to what you need: import { map } from 'rxjs/operators'; getExemplo(id: number): Observable<Exemplo>{ return…
-
3
votes2
answers1430
viewsA: Insert variable in regular expression
Basically, inside a string template, the character \ must be escaped, being written as \\. See the difference: let current_counter = 1; console.log(`/\[${current_counter}\]/g`); // imprime "/[1]/g"…
-
2
votes2
answers176
viewsA: Get how many times each element of a list repeats
I don’t know how you used the Counter, but it does work. Just pass the list directly to it: from collections import Counter clientes = [ 'MARIA', 'JOAO', 'MARIA', 'JOAO' ] counter =…
-
0
votes1
answer257
viewsA: How to identify line end in Javascript / jQuery?
Maybe you don’t even need regex. Just search for elements whose class is stat_col, and use filter to filter these elements by exact text: let cont1 = $('.stat_col').filter(function() { return…
-
3
votes2
answers1704
viewsA: How to send request in Timestamp: yyyyMMddHHmmssffff format using Postman?
In the documentation of Moment.js we can see that for the fractions of a second S (the letter "S" uppercase), so the format would look like this: console.log(moment().format('YYYYMMDDHHmmssSSSS'));…
-
4
votes3
answers168
viewsA: Compare python 'E' letter
The problem is not only the letter "E", but the fact that the code fails when the list current_users has names that mix uppercase and lowercase letters. After all, only in the new_user that you turn…
-
4
votes1
answer294
viewsA: How to convert the String "20190930120000[-3:BRT]" to Localdatetime
The excerpt -3:BRT I believe it’s the offset (-3, the difference in hours with respect to UTC) and the Timezone (BRT is the acronym commonly used for "Brasilia Time", which is the Official Time of…
-
5
votes2
answers1459
viewsA: Traverse two arrays in parallel
If you want to scroll through two lists at the same time, you can use function zip: nomes = ['CARLOS','JOAO','PEDRO'] idades = ['30','25','22'] for nome, idade in zip(nomes, idades):…
-
2
votes1
answer474
viewsA: Remove with regex everything after two points in the SQL query
If there’s only one : in the field, an alternative is: select regexp_replace(hostname,':[^:]+$', '') from hosts; The regex has the character :, and then a character class denied [^:] (any character…
-
20
votes1
answer1140
viewsA: Why should I use Joda-Time or not?
In general, whether or not to use a language/framework/library/technology depends on several factors (from technical aspects to personal taste). In the specific case of Joda-Time, I think it is…
-
3
votes1
answer170
viewsA: Intersection between time
The basic idea is to get the time the session ends (adding the duration to the initial time), and check if the end is after the beginning of the other session (if it is, they interfere with each…