JPA Criteria Expression Replace Character - expression

In type String to replace all - with * I can write
String firstName = firstName.replaceAll("-", "*");
Is there a way to do the same in Criteria Expression?
I need to remove special characters from the first name before comparing it to the pattern in like method.
My expression:
Expression<String> firstName = root.get("firstName");
builder.like(firstName, pattern);

Thanks to #SimonMartinelli comment. My issue is solved by using
builder.function("REGEXP_REPLACE", String.class, firstName, builder.literal("[^a-zA-Z0-9]+"), builder.literal(""));

Related

Replacing GUID in Kusto

How can I replace all GUID's in a Kusto query with no value.
e.g.
my data looks like
/page/1d58e797-a905-403f-ebd9-27ccf3f1d2cd/user/4d58e797-a905-403f-ebd9-27ccf3f1d2c3
and I want
/page//user/
You can use the replace function. Also, you can test regular expression here.
let input = '/page/1d58e797-a905-403f-ebd9-27ccf3f1d2cd/user/4d58e797-a905-403f-ebd9-27ccf3f1d2c3';
let rx = '[({]?[a-fA-F0-9]{8}[-]?([a-fA-F0-9]{4}[-]?){3}[a-fA-F0-9]{12}[})]?';
print replace(rx, '', input);
Try using the below regex It will remove guid (8-4-4-4-12) in url
let regex =/(\/[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})(\b|\/)/g

Passing parameter to Match query in Neo4j using Spring

I am trying to compare node name from Neo4j database with given technology name. I am doing using Spring Application.
#Query("MATCH (n) WHERE n.name =~ '(?i){0}' RETURN n.name")
String getTechnology(String technologyname);
Request is like
MATCH (n)
WHERE n.name =~ '(?i){0}'
RETURN n.name
with params {0=AVM}.
But it's returning null. However, if I do it actual technology name it's working fine.
Pass the parameter as WHERE n.name =~ {0}. What's happening is that the parameter isn't substituted from within the string, so the parameter has no binding in the query, and instead you're searching for the string literal "{0}" which always fails.
If you want to pass a regex as a parameter, you'll need to put the "(?i)" part in the string getting passed, effectively letting your code decide the regex, not just a string inside of it.
You need to separate the regular expression part from the parameter part like this:
#Query("MATCH (n) WHERE n.name =~ '(?i)' + {0} RETURN n.name")
String getTechnology(String technologyname);
As You'd concatenate in Neo4j.

comparing a url containing utf-8 encoded string with a string

I have a url
"/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru"
and a list of key words. I need to determine if the url contains any of those words.
I checked this string %D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80
using
utf-8 encoder
thought I had to change % to \x for it to work.
I try using regular expressions for this
select "/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru" rlike encode("это рэп импр", "UTF-8");
but it doesn't accept a binary as an argument and base64(encode("это рэп импр", "UTF-8")) doesn't return the type of string I need.
My question is, how do I turn this это рэп импр into this %D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80?
Found this
SELECT reflect("java.net.URLDecoder", "decode", "/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru", "UTF-8");

findelement is not throwing NoSuchElementException

I want to write a test to check if a webelement with a specified text is not present on a page. This is the code for the method doing the job:
public boolean checkOfAanvraagIsOpgevoerd (String titel)
{
String quote = "\"";
String titelMetQuotes = quote + titel +quote;
titelMetQuotes = "dierdieboeboe";
boolean isOpgevoerd=false;
try {
driver.findElement(By.xpath(".//*[#id='listRequests']//h4/a[contains(text(),"+titelMetQuotes+")]"));
isOpgevoerd=true;
} catch (NoSuchElementException NE) {
NE.printStackTrace();
}
return isOpgevoerd;
}
Although I'm absolutely sure that there is no a tag on the page wich contains the text "dierdieboeboe" still the catch block is skipped. When I replace for instance h4 in h5 in the xpath expression the NoSuchElementException is thrown as expected. It seems that the contains part in the expression is ignored.
Try this (note the single quotes around the actual text):
By.xpath("//*[#id='listRequests']//h4/a[contains(text(),'"+titelMetQuotes+"')]")
contains is a function that takes two strings. Hence the text of your variable titelMetQuotes needs to be quoted. Obviously, in this case it is easier to use single quotes.
Additionally, the variable name (titel with quotes) is quite misleading because it actually has no quotes for another flaw in the code:
String titelMetQuotes = quote + titel +quote;
titelMetQuotes = "dierdieboeboe";
The second line simply overwrites the quoted title with a non quoted string.
Finally, you don't need the leading dot in your xpath expression in order to locate the first element of any kind with id listRequests

How to remove amp; from URL

I am getting a URL that contains amp;. Is there any way to remove this as currently I tried URLDecode function, but It's not working. Do I need to remove It using simple string replacement or Is there any better way to do this?
As #Lankymart pointed out URLDecode only works on URL-encoded characters (%26), not on HTML entities (&). Use a regular string replacement to change the HTML entity & into a literal ampersand:
url = Replace(url, "&", "&")
In Angular I added amp; to the params names
this.activatedRoute.queryParams.subscribe(params => {
this.user_id = params['user_id'];
this.practice_id = params['amp;practice_id'];
this.patient_id = params['amp;patient_id'];
});

Resources