MongoDB regex query from Spring Boot - regex

I want to keep a regex in MongoDB document like
regexToApply : "someRegularExpression"
and I want to query with a string and get all matching documents from mongo.
I played with $regex, but it's not regular regex operation.It's kind of reverse regex operation. I tried to something like below, but it does not return any document.
#Query("{$where: ?0.$match('regexToApply')}")
List findByRegex(String myText);

You should be able to use $expr with $regexMatch
{$expr: {$regexMatch:{input:"string", regex:"$regexToApply"}}}

Related

Regular expressions (RegEx) to filter string from URLs in Google Analytics

I want to filter a string from the URLs in Google Analytics. This can be done using the Views > Filter > Exclude using RegEx, but I have been unable to get it to work.
An outline of how these filters are set up, can be found here, however, I can not work out how to isolate the string using RegEx. I believe it will need to be one filter per URL type.
The URLs follow this format:
/software/11F372288FA/pagename
/software/13F412C5FA/pagename/summary
/software/XIL1P0BFXCKM81/pagename2
I need to exclude this part of the URL:
/11F372288FA/
So that the URL data (e.g. Session time) is recorded against:
/software/pagename
/software/pagename/summary
/software/pagename2
I have worked out that I can isolate the string using thing following RegEx
^\/validate\/(..........)\/accounts\/summary$
It is not very elegant and would require a filter for every URL type.
Thanks for the help!
I'm not certain if this will work in your exact case but instead of using regex for this it might be easier to just create a new string from the start to the end of "software" and append everything from pagename to the end. In Java this might look something like:
String newString = oldString.substring(0, 9) + oldString.substring(oldString.indexOf("pagename"));
Take note though that this will only work if the "software" at the start is always the same length and you are actually only excluding things between "software" and "pagename".

Regex replace to map paginated URLs to a new format

I'm using a web crawler tool to compare two different website crawls before and after migration and need to map paginated URLs that have changed format.
e.g
Old: https://example.com/page/2/ OR: https://example.com/directory/page/16/
New: https://example.com/?page=2 OR: https://example.com/directory/?page=16
The tool has a regex replace feature for URL maping,
However, I cannot get the regex correct and the end result has an extra forward slash at the end:
https://example.com/?page=2/
What is the correct regex here to get the result I'm looking for?
Regex: /page/([0-9]+)/
Replace: /?page=$1

How to compare two string using RegEx

I have a collection in the MongoDB which has list of URLs like below.
In my business logic for some requirements, I want to check whether the called URL is matching with any of the records in the DB records.
like req.originalUrl i get suppose
/logistics/initiator/5ee7a0be36acdc46ae0576d6/users
But in the above URL obviously, I'm getting the actual Id -- 5ee7a0be36acdc46ae0576d6
What i tried:
I tried manually concatinating the req.baseUrl and req.route.path but that still gives me the below string
/logistics/initiator/:initiator/users
which is again incomparable.
Replace the ID with \{\w+\}, and use that as a regular expression to match against the url column in the table. So the regexp should be /logistics/initiator/\{\w+\}/users.

Replacing Anchor in JSTL

In my JSP I have receive some data which is coming from database my data is for example something like this :
Google is the greatest search engine ever http://www.google.com
what I wanna do is so simple: I want to make this link wrap in anchor tag using JSTL something like:
Google is the greatest search engine ever http://www.google.com
that's all !
take note that the urls are not constant, I mean I'm not sure what that be exactly & I just mentioned google here for the example.
Follow this SO question to create a replaceAll function for JSTL and then use the following pattern to replace the url to html link:
String pattern = "(http:[A-z0-9./~%]+)";
String str = "Google is the http://www.test.com greatest search engine ever http://www.google.com";
String replaced = str.replaceAll(pattern, "<a href='$1'>$1</a>");

Neo4j index query with regex

I am trying to get likers for some artists through an index on Name :
START n=node:Artist(Name =~ 'Michael*.')
MATCH n<-[:LIKES]-liker
return liker.Id, n.Label
LIMIT 50
And I have this error :
Invalid query
string literal or parameter expected
"START n=node:ArtistId(Name =~ 'Michael*.')"
I am wondering how can I use regex in index query?
I know I can use regex in match but I don't know how can I use regex in START.
Thanks for your help
You can't use normal regex syntax, but you can use wildcards:
START n=node:Artist('Name:Michael*')
Edit:
Neo4J uses Apache Lucene for index queries. You have a few other cool things you can do in addition to wildcards.