Posts by hkotsubo • 55,826 points
1,422 posts
-
2
votes2
answers57
viewsA: Changing fields separator for a Macaddress
An alternative is to use split to break the string into an array, and then use join to generate a string again. The parameter of split is the separator (in case, -). With this, an array will be…
-
3
votes3
answers715
viewsA: Read JSON array on Android
Your variable resposta contains all JSON content in one String: [{"RESULTADO":"SUCESSO"}] To transform this String in JSON objects, just use the package classes org.json. If you look at JSON syntax,…
-
4
votes2
answers399
viewsA: Is there a method in Python similar to x.find(string), but which returns all occurrences?
For this specific case, where you only want to search for the occurrence of a single letter, you can go through the string with enumerate, so you can have at once the index and its character in that…
-
1
votes2
answers1005
viewsA: Extract only the name of a file from the full path
As it comes to the path of a file, another option is to use the command basename: basename /home/42/teste.txt The exit is: teste.txt Within a script, just run the command with the syntax of command…
-
2
votes1
answer1026
viewsA: Convert Java object to JSON with Gson (generating with backslash)
I did a basic test with version 2.8.5 of Gson: Gson gson = new Gson(); Documento documento = new Documento("bene1"); System.out.println("gson.toJson(documento): " + gson.toJson(documento)); The way…
-
3
votes2
answers193
viewsA: Jsonobject with multiple values without using Array
If you refer to JSON syntax will see that { and } delimit a Object, which is nothing more than a set of key pairs/value. Now, analyzing the JSON you want to create: { "auth": { "user": "rbz",…
-
4
votes2
answers382
viewsA: Regular expression that finds patterns in which some terms can change?
Short answer Use re.split instead of a super-regex-do-it-all. Long answer You can, if you want, try to make a single regex that solves everything (although I don’t think it’s the best solution, keep…
-
2
votes1
answer145
viewsA: Return block-defined substring in Python on first occurrence
This happens because the quantifier * is greedy (Greedy quantifier): he tries to grab as many characters as possible that satisfies the expression. To cancel greed, just put one ? shortly after the…
-
0
votes3
answers3774
viewsA: Write text to Shell Script
You can use the option -e of echo, which allows them to be placed \n and these are interpreted as line breaks: echo -e "$variavel1 linha\n$variavel2 linha\n$variavel3 linha\nquarta linha" Another…
-
3
votes1
answer76
viewsA: Regular Expression to clone a value in a field
I think it’s easier for you to make one split, separating the fields by | and then concatenating what you need, but if you want to use regex, let’s go. If your entries are always separated by | and…
-
16
votes5
answers10820
viewsA: How to Reverse a String?
Just complementing, the solution proposed with StringBuilder works very well, but there are cases that are not covered, if we take into account all the possibilities of Unicode. An example is when…
-
2
votes1
answer122
viewsA: Data from an object is null after reading from a CSV
You must add the setters in class Pessoa: public class Pessoa { .... public void setEmployee_name(String employee_name) { this.employee_name = employee_name; } public void setUser_id(String user_id)…
-
7
votes2
answers321
viewsA: How to emulate the regular expression reset branch in Java
I found an alternative not very "elegant" (and with limitations, explained below), using replaceAll: String regex = "(?:([aeiou]+)[0-9]+|([123]+)[a-z]+)\\W+";…
-
15
votes2
answers321
viewsQ: How to emulate the regular expression reset branch in Java
I have this regex: Pattern p = Pattern.compile("(?:([aeiou]+)[0-9]+|([123]+)[a-z]+)\\W+"); Basically, it has the following parts: one or more lower-case vowels ([aeiou]+), followed by one or more…
-
2
votes2
answers210
viewsA: How to change the file extension recursively in GNU/Linux?
The problem is that basename removes the information from the folder and returns only the file name. So the idea is not to use it, so that this information is not lost. To manipulate the file name,…
-
6
votes4
answers148
viewsA: My functions only return 0
In addition to what they have already said in the other answers (you should only take the values after the Submit and the string values must be converted to numbers), it can simplify the code,…
-
7
votes2
answers22159
viewsA: How to change time zone (GMT) date and time in JS
First let’s understand what represents a Date in Javascript. According to the documentation, is an object representing the amount of milliseconds since 1 January 1970 at midnight, in UTC (this date…
-
6
votes2
answers1974
viewsA: Pick URL with regular link expression
First let’s see some details on its regex (and also suggestions to improve it). Use .* is always tempting, but "dangerous", since it is an expression that means "zero or more occurrences of any…
-
1
votes1
answer593
viewsA: capture Pattern groups with regex
The problem of using . is that it matches any character, and so it’s too comprehensive and may end up picking up parts of the string that you don’t want. The best is say exactly what you want. In…
-
2
votes2
answers2340
viewsA: Error: "java.text.Parseexception: Unparseable date: "2018-11-14T12:12"
DateTimeFormatter is part of the API java.time, which was introduced in Java 8 and is incompatible with the old API (although it is possible to convert between Apis, more about this below). If you…
-
3
votes1
answer465
viewsA: What is this information next to the commit ID?
origin/feature/chart is basically the branch called feature/chart who is in the origin. This means that that commit matches this branch. To see which one is yours origin, spin: git remote show…
-
6
votes2
answers4377
viewsA: Regex for monetary values
To validate if the string is in this format, you can use ^[1-9]\d{0,2}(\.\d{3})*,\d{2}$: ^ and $ sane markers for the beginning and end of the string. So you ensure that the string will only have…
-
3
votes2
answers867
viewsA: Replace string with regex in python 3
Your input string is a JSON, so you better use the right tools to manipulate this data. You can use the module json and then manipulate the URL with urllib.parse: # -*- coding: utf-8 -*- import re…
-
9
votes2
answers12531
viewsA: Check for special characters in a string using Regexp
Only to complement the another answer, would like to give another alternative to the solution. You said you want to validate a password field and allow it to have special characters (plus letters…
-
2
votes2
answers3264
viewsA: Convert the timestamp result to the formed Date and Time
I saw that your Java class is using a LocalDateTime, then there are some details to be attentive, before leaving by doing whatever conversion. I already say that I do not know the details of how…
-
1
votes1
answer185
viewsA: Search for specific information in the digital certificate array
It’s been a while since I programmed in PHP and certainly the codes below are not the best, but as the focus of the question is on the fields of the certificate, I thought it was worth a reply. The…
-
4
votes1
answer277
viewsA: Doubt Regex functionality - Java
Basically, this regex checks whether a String corresponds to an email address. But it may also end up accepting "weird" things (more on that at the end). Analyzing the regex in detail:…
-
4
votes1
answer1269
viewsA: Regex for repeat numbers on CNPJ
Short answer ^(?!(\d)\1\.\1{3}\.\1{3}\/\1{4}-\1{2}$)\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$ I’m not sure the hyphen needs to be escaped with \\, as you did. If you need to, just change the regex to:…
-
2
votes1
answer142
viewsA: Regular Expression is correct but does not enter if
The problem with regex is that there are several Flavors (flavors) different. I would say that if regex were a language, it would have several dialects (including, in some documentations, these…
-
11
votes5
answers2803
viewsA: How to make CSS a paragraph with Capitular letter (Drop Caps)
Just use the pseudo-element first-letter, which, as its name says, corresponds to the first letter of the element in question: p::first-letter { font-size: 2rem; font-weight: bold; color: red; }…
-
2
votes3
answers1246
viewsA: Regular expression for 2 specific cases
First let’s see why your regex doesn’t work. The clasps ([]) correspond to a character class: they serve to indicate that you want any character within them. For example, [abc] means "the letter a…
-
12
votes3
answers193
viewsA: Regex for this format xxxxxxxxxxxx_v2
The other answers suggested using \w, which actually accepts alphanumeric characters (letters or numbers), but also accepts the character _. Does that mean that ^\w{32}_v2$ also considers a string…
-
3
votes2
answers69
viewsA: String containing only numbers
You can use this regex: ^[0-9]+$ The markers ^ and $ indicate, respectively, the beginning and end string. This ensures that the string will only have, from start to finish, what is specified…
-
1
votes3
answers7105
viewsA: Convert String with date to Datetime in Java
Just to update the answers (which are not wrong), from Java 8 you can use the API java.time to manipulate dates. This API works in a similar way, but there is some important differences in relation…
-
2
votes1
answer2159
viewsA: How to generate Timeformatter in YYYY-mm-Ddthh:mm:ss-TZ format
The classes of java.time already do strings in ISO 8601 format, which is the format your string is in. You said you want one LocalDateTime, but in your code you’re using LocalDate. Either way, it is…
-
7
votes1
answer109
viewsA: Display only option marked in select in JS
You can use addEventListener('change', ...) and define a function that will be called whenever the select is amended. In this function, just take the selected value in the select and loop the rows…
javascriptanswered hkotsubo 55,826 -
6
votes1
answer618
viewsA: Regular expression does not validate password when I type only numbers
First let’s look at your regex and understand why it doesn’t work: ^[A-Za-z0-9]*\d+[A-Za-z0-9]*$ The markers ^ and $ indicate, respectively, the beginning and end of the string. Then we have…
-
5
votes2
answers1681
viewsA: Regex required number(s) and optional letters
Just to give another option, this regex requires at least one number (and the rest of the characters can be letters or numbers): ^(?=.*\\d)[a-zA-Z\\d]+$ But it doesn’t work exactly the same as…
-
3
votes2
answers926
viewsA: Recursive function to calculate the number of lowercase letters in a character string
The easiest way is to scroll through the characters of String with a for simple, but if you really want to do recursive, come on... First of all, this function is not exactly recursive: public…
-
0
votes2
answers99
viewsA: invalid.syntax appears when the program is run
As you said, close the parentheses of str. But in fact, input already returns a string, so str is not necessary in this case. Another thing is the condition of while. The or is true if any of the…
-
3
votes3
answers801
viewsA: Explanation of the function and application of the javascript Sort function
Thinking of ordering in a generic way, there are several different algorithms (each one with its particularities), but one thing they all have in common: at some point, they need to compare two…
-
0
votes3
answers83
viewsA: How to consult register that does not contain a certain code?
An alternative is first you make a subquery with the calls that have the action 140, and then you make a select in the calls that nay are in this subquery: select * from tb_chamados where…
-
3
votes2
answers252
viewsA: How to separate data from arrays into lines?
You are traversing the array with each, and the variable a represents, at each iteration, a array with the players of the team. When playing the whole array a within the li, you are putting all…
-
7
votes3
answers334
viewsA: What’s the difference between throw and Alert
Actually what happens is this: the throw throws an error this error is caught by catch the catch flame alert(e) Example: try { throw "erro!"; } catch(e) { alert(e); } Will be shown the alert with…
javascriptanswered hkotsubo 55,826 -
2
votes3
answers232
viewsA: Convert Date to date field
Do split and reverse, as the other answers suggest, it works well if the date typed is valid. But as the date is being typed in a field input type="text", means that any value can be entered into…
-
7
votes3
answers789
viewsA: How is a REGEX Javascript for Mail Tracking Code (AZ123456789AZ)
Only to complement the user reply @Paz, a brief explanation as to why your attempt did not work. The brackets define a class or character set. For example, [ABC] means "the letter A or the letter B…
-
5
votes1
answer2803
views -
8
votes2
answers1988
viewsA: How to get the last day of a month with Momentjs?
The solution is to use endOf('month'), like your own response indicates. There is only one detail: this method also changes the time. See in the example below: console.log(moment([2018, 8,…
-
3
votes1
answer628
viewsA: How to get the size of a string array in the shell script?
Actually you don’t need the size, just use tr to exchange the comma for \n and go through the result with for: for i in $(echo "2,3,4,5" | tr "," "\n") do echo $i done This prints: 2 3 4 5 In fact,…
-
3
votes2
answers110
viewsA: How to do for every time you pass "true", it print the entire instantiated object?
The method contains returns a boolean, so the code only prints true or false. If you want to print products that meet a condition, you can make a for simple as suggested by Maniero. Another option…