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

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.

Related

Using regex in facet.contains Solr

I have solr field stored as -
record1 --> colorDimension : "Purple|91"
record2 --> colorDimension : "Purple|974|91"
record3 --> colorDimension : "Purple|974"
I need to facet on this colorDimension Field in a way such that term contains "Purple" and number "91".
The result I am targeting is -
Purple|91 = 2
I was looking out for facet.contains but did not get any examples that uses regular expressions.
You should expand these while indexing, so that you have a token for Purple|91 and Purple|974 separately. Faceting is quick because it can count tokens, without having to run a regex against each one to find the actual value.
You'll probably have to do this in your code, since I don't think you can make the pattern regex tokenizer spit out multiple tokens for a given prefix / group.
Try using this pattern:
Purple\|(?:\d+\|)*91(?:\||$)
Demo
If you actually need to make use of regular expressions, there is a parameter facet.matches, which can be used to specify a regular expression to restrict the facet results

Regex HTTP Response Body Message

I use a jmeter for REST testing.
I have made a HTTP Request, and this is the response data:
{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}
I need just the ID (which is 11) in
{"id":11,....
I use the REGEX below :
([0-9].+?)
It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :
([0-9][0-9].+?)
Is there any dynamic REGEX for my problem. Thank you for your attention.
Regards,
Stefio
If you want any integer between {"id": and , use the following Regular Expression:
{"id":(\d+),
However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.
I suggest using the following regular expression:
"id":([^,]*),
This will first find "id": and then look for anything that is not a comma until it finds a comma. Note the character grouping is only around the value of the ID.
This will work for ANY length ID.
Edit:
The same concept works for almost any JSON data, for example where the value is quoted:
"key":"([^"]*)"
That regular expression will extract the value from given key, as long as value is quoted and does not contain quotes. It first finds "key": and then matches anything that is not a quote until the next quote.
You can use the quantifier like this:
([0-9]{2,}.+?)
It will catch 2 or more digits, and then any symbol, 1 or more times. If you want to allow no other characters after the digits, use * instead of +:
([0-9]{2,}.*?)
Regex demo

How to match jre1.5.0_14 via regex?

I am trying to search all the registry keys and check the data if there is any jre1.5.0_14. I wonder how can I match jre1.5.0_14 via regex?
Thanks in advance.
Best Regards.
There is no point in using regular expressions when you're looking for a particular (sub)string. String functions provide better performance in that scenario:
If InStr(str, "jre1.5.0_14") > 0 Then
'do something
End If
Regular expressions are useful when you want to match a variety of (sub)strings, for instance JRE 1.5 updates 14 through 17:
Set re = New RegExp
re.Pattern = "jre1.5.0_1[4-7]"
If re.Test(str) Then
'do something
End If

Searching a number in a specific string with regexp in jmeter

I want to find a specific number from a HTML response.
For example, I want to extract 3 from publicationID3publicationID.
Does someone know a solution with regexp?
Add Regular Expression Extractor Post Processor as a child of the request, which returns to you this string.
Configure it as follows:
Reference Name: publicationID (you can use any variable name here)
Regular Expression: publicationID(\d+)publicationID
Template: $1$
other fields can be left blank.
You can later refer publication ID as ${publicationID} or ${__V(publicationID)}
You can see what matches does your Regular Expression return using View Results Tree Listener (select RegExp Tester from dropdown). Another option is Debug Sampler again with combination with View Results Tree.
you can use \d to match a number using regex.

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.