Posts by hkotsubo • 55,826 points
1,422 posts
-
2
votes1
answer69
viewsA: Function to check if the year changes
If you want to add months to the current date, just do: Data = DateTime.Now.AddMonths(i - 1); When you do DateTime.Now.ToString("dd") + "/" + ..., you are creating a string. Next, DateTime.Parse…
-
6
votes1
answer138
viewsA: Why does my program only work if I avoid parse Try catch?
There’s no way the setTime fall into the try/catch of parse, for the call of setTime, besides afterward, is out of of try/catch. What happens is this: dateValue contains the String "15 Apr 2019" (as…
-
1
votes4
answers2211
viewsA: Javascript converting wrong date
When you pass a string in this format to the builder of Date, he uses the same method rule Date.parse(). In this case, the string contains only day, month and year in format ISO 8601, and this…
-
3
votes3
answers118
viewsA: Where am I going wrong to calculate age?
To calculate the difference between two DateTime's, just use the method diff: $date1 = new DateTime("2000-01-20"); $date2 = new DateTime("2019-04-23"); $interval = $date1->diff($date2); echo…
-
2
votes1
answer534
viewsA: Catch string inside a text file using regex in Python
The function open returns a file object, while the function findall should receive a string. That’s what the error message is saying: Typeerror: expected string or bytes-like Object You passed the…
-
2
votes1
answer113
viewsA: Repeat record in database on same day of each month
If you want to add up 1 month, you don’t need to make a loop adding up days, you can directly add up a DateInterval corresponding to one month: $d = new DateTime(); $d->setDate(2019, 5, 20); //…
-
2
votes1
answer239
viewsA: Regex to remove HTML Entity
A HTML Entity is perfectly valid information in an HTML and there is no reason to remove it. What you can do is Decode of his, using HttpUtility.HtmlDecode (available in namespace System.Web), or…
-
4
votes1
answer193
viewsA: How to mount a Regex to identify the state of the interfaces
Need to be with regex? You can use awk to take only the field corresponding to the status, and pass the interface name as parameter of the command ip: ip link show eth0 | awk '{print $9 }' First, ip…
-
3
votes1
answer699
viewsA: Regex to validate a 5-digit alphanumeric field
\d{0,5} means "from zero to 5 digits". But from what I understand, you want it to have at least one digit at the beginning, so could change to \d{1,5} (between 1 and 5 digits). But if we look at the…
-
3
votes2
answers208
viewsA: Catch everything between line break tags
The ideal is to use a parser HTML, as it can handle all possible and valid cases of HTML syntax, which are much more difficult to deal with regex. That said, let’s go to some alternatives... By…
-
2
votes1
answer42
viewsA: Regex for two string hypotheses simultaneously
You can use this regex: b\d{4}\s[a-zA-Z]{3,4}(-\d)? Detail: the brackets define a character class. For example, [ab] means "the letter a or the letter b" (any of them). But when you only want a…
-
4
votes2
answers253
viewsA: Extract content from "Name:" field until end of line
Depends on how your string is. If after "Nome: " only has the name and soon after the line break, the simplest is to use: import re s = 'a1in1iionia\n\nDados do cliente\nNome: Foo\nE-mail:…
-
2
votes4
answers6985
viewsA: How to add times in Java?
First, we have to understand the difference between times and durations: one timetable represents a specific moment of the day. Ex: the meeting will be at two o'clock in the afternoon (it says…
-
1
votes2
answers134
viewsA: addeventlistener executes a function even before it is called
addEventListener must receive a function (or a EventListener) in the second parameter. But in doing teste() (with the parentheses), you are calling for the function (executing her), and her return…
javascriptanswered hkotsubo 55,826 -
3
votes1
answer531
viewsA: Grab only some attributes of HTML tags
As you mentioned the curl, I am assuming that you have a string containing all the HTML. In this case, an alternative is to use the GIFT EXTENSION: $html = <<<HTML <html> <body>…
-
1
votes1
answer104
viewsA: Subtract 4 times and display at the same time the result in another input
First, you could use the input type="time" instead of type="text". If the browser is compatible and support this type, it already limits the input format to hh:mm (if the browser does not support,…
-
3
votes2
answers3481
viewsA: Regex for strong password
To response from Monneratrj It already solves most of what you need. I would just like to add a regex to check the last condition (do not allow two or more identical consecutive characters, such as…
-
3
votes1
answer645
viewsA: How to create a regex to delete letters and number after the 3rd decimal place
The regex you used (/\d|,/) means "a digit or a comma", which means that you are replacing the numbers and commas with '' (that is, is removing all numbers and commas from the string). I suggest…
-
0
votes1
answer102
viewsA: Find via SSH on multiple servers
First you can create a script that searches the two Jvms of the same server: #!/bin/bash cd for dir in log_vm_1 log_vm_2 do echo "procurando em" $(hostname) $dir find $dir -type f -exec grep -l…
-
1
votes2
answers258
viewsA: How to add 2 days to a date and put the value in HTML
To add two days to a date, just use one Date and add 2 to the value of getDate() (using setDate to update the value): let d = new Date(); // data atual d.setDate(d.getDate() + 2); // somar 2 dias…
-
2
votes1
answer514
viewsA: Fractions of 15 minutes in the PHP time log
Since you are working with the difference in minutes, you can ignore the seconds, then the first thing is to divide the difference by 60: $totalMinutos = ($horaFinal - $horaInicial) / 60; Then just…
-
20
votes3
answers4338
viewsA: What is the "line break" in a Regex?
First let’s see what it says to job documentation str_extract_all: Extract All Pieces Of A String That Match A Pattern. Extracts all parts of a string that match a pattern Well, the regex you used…
-
1
votes2
answers466
viewsA: Reading JSON with many PHP arrays
To manipulate a JSON, you first need to know your syntax. When JSON is delimited by keys ({ and }), it corresponds to a JSON Object, which is a set of several pairs "key/value". For example: {…
-
3
votes2
answers2506
viewsA: Change only hours, minutes, seconds of a Date object
First we have to understand what really class java.util.Date means. Despite the name, it does not represent a date. At least not in the sense of representing a single day, month, year, hour, minute…
-
8
votes2
answers135
viewsA: Difference between metacharacters . * and +
To Reply from @Lipespry already explains very well the differences, I would just like to complement with some details. The first - and maybe I’m being a bit pedantic - is that .* sane two…
-
1
votes2
answers186
viewsA: Unexpected output when printing substring
You can call the awk directly at the exit of find, without needing the exec: find ./ | awk -F"/" '{print $2}' Only that find ./ also includes the current directory, which means that it also returns…
-
14
votes7
answers620
viewsA: How to access a circular array?
An alternative is to use closures: function makeCircular(arr) { var current = 0; return function() { return arr[current++ % arr.length]; } } const a = ['A', 'B', 'C']; let next = makeCircular(a); //…
-
6
votes3
answers4376
viewsA: Current date and time in time zone timestamp format
This format you are wanting (2019-03-28T15:14:19.000Z) is defined by the standard ISO 8601. Either way, this one Z at the end is an important information because indicates that the date/time is in…
-
1
votes1
answer459
viewsA: Very slow recursive Fibonacci method, what is the cause?
As explained in this answer, the problem is the recursion itself, and not the input and output of the data (up because you only use the Scanner and the println few times and outside the recursive…
-
1
votes1
answer340
views -
3
votes3
answers1730
views -
1
votes1
answer93
viewsA: Regex separates by type of occurrences, how to do and the simple way to achieve?
Creating a regex that interprets all (or several) user Agents is a very difficult task, since the format is very open and cover all cases seems unfeasible to me. An alternative is to use the…
-
1
votes4
answers7937
viewsA: How can I increment a day to a Java date?
The question says "increment a date of the type DD/MM/YYYY", but none of the answers focused on this specific format. Anyway, this is a great opportunity to clarify that, as already said here, here…
-
7
votes2
answers806
viewsA: Regex date validation with 2/2/4 characters
Honestly, this regex that you are using, in my opinion, is nothing practical and I would avoid using in any system in production. Just see the difficulty you’re having to understand and modify it.…
-
7
votes2
answers1284
viewsA: Foreach with lambda which returns the sum of iterated items
Why not use a for simple? private double getValorVenda() { double valor = 0.0; for (Produto produto : produtos) { valor += produto.getValor(Venda.class); } return valor; } The method forEach serves…
-
3
votes1
answer152
viewsA: What kind of data to store "2019-02-06T14:14:38+00:00"?
Before talking about Mysql, a short summary about some concepts. The value 2019-02-06T14:14:38+00:00 contains 3 pieces of information: the date (2019-02-06) the time (14:14:38) the offset (+00:00),…
-
1
votes3
answers2069
viewsA: Calculate the arithmetic mean of the integers between 15 (inclusive) and 100 (inclusive)
"Whole numbers between 15 (inclusive) and 100 (inclusive))" means that are all the numbers on this list: 15, 16, 17, 18... up to 100. "Arithmetic mean" of a set of numbers is simply the sum of those…
-
1
votes2
answers201
viewsA: switch case in bash
In the getopts you must pass the options that are accepted. As it does not have the letter i, it will not be recognized. Putting only the options that are in the case, gets like this: while getopts…
-
6
votes1
answer181
viewsA: Regex using preg_replace to separate values according to ")"
When you just want to pick up a single character, you don’t need the brackets: preg_replace('/\)\s/', ') --> ', '1 () 2 () 3 ()'); Upshot: 1 () --> 2 () --> 3 () The brackets define a…
-
12
votes2
answers3404
viewsA: How do I migrate from Date and Calendar to the new Java 8 Date API?
Complementing the victor’s response, follow a few more points to note when migrating from one API to another. In the text below I sometimes refer to the java.time as "new API" (despite being…
-
1
votes1
answer159
viewsA: Manipulating divisible 3 and 5
As I understand it, options 1, 2, and 3 are exclusionary: only one of them must be executed. But in your code, when the number is multiple of 5 and 3 at the same time, it falls in two if's: in what…
-
4
votes1
answer200
viewsA: How to create simple list from composite list?
Each element of a is a tuple with 3 numbers. To join them together, you can turn them into string, join everything with join and convert the result back to number: a = [(1, 2, 3), (4, 5, 6), (7, 8,…
-
18
votes5
answers5490
viewsA: Count the number of months between one date and another
First we need to understand two important concepts: one date is a specific point of the calendar. Ex: today is 21/03/2019 (March 21, 2019) one duration That’s a lot of time. Ex: I lived in City X…
-
1
votes1
answer241
viewsA: Remove comments from HTML
The s/ and //g are not part of regex itself. This syntax is used in other languages (and in some commands, such as sed), but in Java you only need to pass the regular expression as parameter:…
-
3
votes2
answers197
viewsA: Regex able to ignore the prefixes of a word
You can use \b, which is a word Boundary (in the absence of a better translation, it is something like "boundary between words"). Basically, it serves to indicate positions of the string that have…
-
3
votes1
answer76
viewsA: REGEX extract everything from a group
By default, the point does not consider line breaks, then .* only goes until the next line break and can not go forward (and as the g-img is not on the same line as g-card, he finds nothing). Many…
-
2
votes2
answers255
viewsA: Regex take value from previous line
I don’t know in detail what software you are using, but how you are testing on the site regex., I’ll assume the resources PCRE are available. (basically there are several "Flavors" different from…
-
1
votes2
answers150
viewsA: Regular expression validation is invalid even when you find a match
Let’s look at the method that validates email: def __validaEmail(self, email): result = re.match('(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)', str(email)) if result == None: return False…
-
2
votes1
answer88
viewsA: split does not return array with the string elements
According to the documentation, the method parameter split must be a regular expression. And as in regular expressions the point has special meaning (means "any character"), he must be escaped with…
-
1
votes1
answer121
viewsA: Regex to get comments from a CSS
Just add the two bars, the space after them and the rest of the text in regex: preg_match_all('/\s*\\--([A-Za-z1-9_\-]+)(\s*:\s*(.*?);)?\s*\/\/\s*(.*)/', $css, $resultado); Bars shall be written as…