Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Edit 1:
Please don't go by the example in a literal way. The key values can be of any string. Need not include "key" and "col" in them.
For example, the string can be the following
Ravi,India,Married;John,Canada,Single;Robert,Spain,Unknown
So, if I pass Ravi as the key, I should get India and Married as the result.
I am trying to use the Java regex pattern to find the details from a given string. The structure of the string is as follows:
Key1,Key1Col1,Key1Col2;Key2,Key2Col1,Key3Col2;Key3,Key3Col1,Key3Col2
where ; is the delimiter for each record.
My requirement is to accept the Key (which is Key1, Key2 etc.) and return the corresponding values like Key1Col1,Key1Col2 etc.
This would do it:
(?<=^Ravi,|;Ravi,)[^;]+
https://regex101.com/r/Tcmzhd/1
The link above shows PHP but it should work in Java no problem.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I have a list of strings in random format:
AppName-ver-1.1.0-data.exe
AppName-ver-1.1.1-secondData.exe
AppName-ver-1.2.0-data.exe
AppName-ver-1.2.1-data.exe
AppName-ver-1.2.3-data.exe
AnotherAppName-ver-1.0.0-data.exe
AnotherAppName-ver-1.0.0-secondData.exe
What would be an efficient way in java to find the closest value to string:
AppName-ver-1.2.4-data.exe
UPD: closest - by the naming not length so AppName-ver-1.2.3-data.exe is the expected result
To emphasize what commenters already pointed out:
If you define 'closest' to be the string length, then
AppName-ver-1.2.4-data.exe has the value 26, and
AppName-ver-1.1.0-data.exe
AppName-ver-1.2.0-data.exe
AppName-ver-1.2.1-data.exe
AppName-ver-1.2.3-data.exe
all resemble 26 as well so they are a direct match.
You could also define 'closest' to have the least Hamming Distance. This will give completely different results and AppName-ver-1.2.0-data.exe might win as it is just one bit off.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an encoded string stored in my DB that kinda looks like this (altered for confidentiality):
\x7b22747c
How do I decode this string? (Using either Java or Python)
There is code elsewhere that used tobytes() function to decode it. But I don't own the code so I am not sure what it's doing.
The comments helped in looking in the right place.
Here is what worked for me:
bytes.fromhex('7b22747').decode()
So I just had to remove the \x and then just decode the remaining string which was an encoded hex string.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
When I use [^abc] it excludes a,b,c but I want to exclude only abc not a,b,c.
Just in principle? There are several ways to do it, depending on your context. You could use a negative lookahead, for example, which will assert what the following string must not look like.
Example text:
aba abc abx
Expression:
\b(?!abc)\w{3}\b
Matches:
aba, abx
You should update your question with context if you want specific help.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm using Spring Boot 2 and the JPARepository, i need to return the rows that include in a field a word.
Example, i want to return all the rows where in A field there is the word "SearchMe".
What method i have to use?
(For now the word is always in the start of the string, but will be better if search in all the positions.
findByAStartsWith (String search)
findByAStartingWith (String search)
findByAisStartingWith (String search)
findByAContaining (String search)
and what difference is there?
Thanks so much.
You can make use of % in JPQL Query.
#Query("Select a from TableName a where a.A like %:search%").
or From Spring Data proxies like
findByAContaining(String search);
For Reference - https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
You should use
List<Entity> findByALikeIgnoreCase(String searchString);
Because you will not need to prepend and append %, Additionally it is case-insensitive.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In groovy is there a specific way to remove a value from a collection. For example I have a list of form fields but two of them are hidden fields and I'm trying to figure out how to remove them from the collection. The two parameters I'm trying to remove are salesKey and topicSelection. Groovy newbie so code samples are most helpful
request.requestParameterMap.collect { key, value -> "$key: ${value[0].string}" }.join("\n")
key.remove("salesKey")
key.remove("topicSelection")
I think you could use findAll:
request.requestParameterMap.findAll { key, value ->
!( key in ["salesKey", "topicSelection"] )
}
Check out this answer.
Also, depending on your specific aims, there are a couple of other ways to remove a pair, including dropWhile (which is more or less iterating over your data struct) and minus (which isn't so much removing a pair as creating a new structure without the specified pair). Official doc here.