Neo4j index query with regex - 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.

Related

MongoDB regex query from Spring Boot

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"}}}

Use Nifi replaceText to swap first or last occurance of char/string with another string?

Trying to add tag to incoming nifi json flowfile.
Input:
[{"HIT":"DUMMY_3","BatchId":"jkajks981n-1280189nd-129dnbj-2349nbfk","Id":"81274376231"}]
Expected output:
[{"nifi_received_ts_est":"2018-10-04 09:31:50.108","HIT":"DUMMY_3","BatchId":"jkajks981n-1280189nd-129dnbj-2349nbfk","Id":"81274376231"}]
Tried different methods and am close to this now:
Search Value: ^([^\[]*)
Replacement Value: [{"nifi_received_ts_est":"${now():format("yyyy-MM-dd HH:mm:ss.SS")}"\,$2
Replacement Strategy: Regex Replace
Evaluation Mode: Entire Text
But result is not what is expected. getting below:
[{"nifi_received_ts_est":"2018-10-04 09:31:50.108",$2[{"HIT":"DUMMY_3","BatchId":"jkajks981n-1280189nd-129dnbj-2349nbfk","Id":"81274376231"}]
Never was good in regexp... :( can someone help with the correct phrase to search and replace? Also if someone can explain the regexp and how grouping is done it would help as well. Perhaps a good cheatsheet reference. What is a good site to test and parse nifi specific regexp expressions?
SOLUTION:
If it helps anyone found the pattern: Search Value: ^(.*?)[{ (will do lazy search until finds first '[{' and groups stuff before it to $1) so replacement will be: $1{"nifi_received_ts_est":"${now():format("yyyy-MM-dd HH:mm:ss.SS")}",
change the search value to ^(\[\{)(.*)
in this case the first group (\[\{) will match first two symbols
and the second group (.*) the rest of the string
I'm not sure why you're trying to use a regex here. The correct approach would be to decode the JSON string into a Perl data structure, add your new data to the structure and then encode it back to JSON.
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use JSON;
use Time::Piece;
my $json_parser = JSON->new;
my $json = '[{"HIT":"DUMMY_3","BatchId":"jkajks981n-1280189nd-129dnbj-2349nbfk","Id":"81274376231"}]';
my $data = $json_parser->decode($json);
$data->[0]->{nifi_received_ts_est} =
localtime->strftime('%Y-%m-%d %H:%M:%S');
$json = $json_parser->encode($data);
say $json;

in regex get a single match just before the match pattern?

I have a response like below
{"id":9,"announcementName":"Test","announcementText":"<p>TestAssertion</p>\n","effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":103,"announcementName":"d3mgcwtqhdu8003","announcementText":"<p>This announcement is a test announcement”,"effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":113,"announcementName":"asdfrtwju3f5gh7f21","announcementText":"<p>This announcement is a test announcement”,"effectiveStartDate":"03/02/2016","effectiveEndDate":"03/03/2016","updatedDate":"02/29/2016","status":"InActive","moduleName":"Individual Portal"}
I am trying get the value of id (103) of announcementName d3mgcwtqhdu8003.
I am using below regEx pattern to get the id
"id":(.*?),"announcementName":"${announcementName}","announcementText":"
But it is matching everything from the first id to the announcementName. and returning
9,"announcementName":"Test","announcementText":"<p>TestAssertion</p>\n","effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":103,"announcementName":"d3mgcwtqhdu8003","announcementText":
But I want to match only from the id just before the required announcementName.
How can I do this in RegEx . Can someone please help me on this ?
As an answer here as well. Either use appropriate JSON functions, if not, a simple regex like:
"id":(\d+)
will probably do as the IDs are numeric.

Regex Assistance for a url filepath

Can someone assist in creating a Regex for the following situation:
I have about 2000 records for which I need to do a search/repleace where I need to make a replacement for a known item in each record that looks like this:
<li>View Product Information</li>
The FILEPATH and FILE are variable, but the surrounding HTML is always the same. Can someone assist with what kind of Regex I would substitute for the "FILEPATH/FILE" part of the search?
you may match the constant part and use grouping to put it back
(<li>View Product Information</li>)
then you should replace the string with $1your_replacement$2, where $1 is the first matching group and $2 the second (if using python for instance you should call Match.group(1) and Match.group(2))
You would have to escape \ chars if you're using Java instead.

MongoDB Regular Expression: Contains an e-mail inside a string

Given that I have a string such as
"Donald Trump <donald#trump.com>"
"Art Job <art#job.com>"
How can I find every row that contains "donald#trump.com" using MongoDB in Rails?
Thanks
From the documentation:
search_string = params['search']
# Constructor syntax coll.find({"name" => Regexp.new(search_string)})
# Literal syntax coll.find({"name" => /#{search_string}/})
Beware though... You can't use an index with this query since your regex isn't anchored to the front of the string.
You can perform such a search only using regular expressions:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
In your case you won't be able to search in a efficient way except you denormalize your data and store your email addresses in a dedicated attribute of the document.
No idea about Ruby but every driver should have support for regular expressions.