mongodb regular expressions matching - regex

i am having these kind of strings
"abc?ref1=app";
"abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
where xxxxxxxxxxxxxxx is some string...
i want to write regular expression which should only match "abc?ref1=app" types of strings and should not match any other string like "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx" ..i mean it should only and only match "abc?ref1=app" type of strings...
i have written some thing like this /abc\?ref1=app/ ..but this will also match "abc?ref1=app&xxxxxxxxxxxxxxxxxxxxxxxxxxx"
please tell me how to write regular expression which will only match "abc\?ref1=app"

You do not even need regex here, since mongoDB uses lexographical comparison
a simple
{ "myStr" : { $lte : "abc?ref1=app" }
where myStr is your db key
will work
a string like abc?ref1=app&xyz would be counted as greater than your query.

Add an end-of-line ($) token
abc\?ref1=app$

Related

Does mongo regex query have character limit, if the regex search string is more than that limit it throws error

I am seeing mongo regex query not returning result when the regex searched string is very big, instead its throwing error. I have a scenario where I append lot of names to do a regex and thus my regex search string goes beyond 40000 characters.
eg:
db.getCollection('collection').find(
{"name":{"$regex" :"name1 | name2 | name3", "$options":"-i"}}
)
Can you explain why you are doing this?
The idea of a regex is to create a expression with which you match (multiple) value(s).
example expression:
name\d+
will match on all "namex" vales where x is a decimal.
The idea will be to create a single expression to fullfill your query requirement.
When you want to match on multiple string values you can use $and operator
Yes, mongoDB regex has character limit, originates from perl regex limit.
Because "MongoDB uses Perl compatible regular expressions (i.e. “PCRE” ) version 8.41 with UTF-8 support."MongoDB v3.2
You can see the limitation is 32764 characters:MongoDB add assert of regular expression length
I recently met this issue, and the solution was to use $in query operator instead. $in does not have characters limit. This suits my problem, since it was exact match rather than pattern matching in such long input case.

Regular Expression to unmatch a particular string

I am trying to use regular expression in Jmeter where in I need to unmatch a particular string. Here is my input test string : <activationCode>insvn</activationCode>
I need to extract the code insvn from it. I tried using the expression :
[^/<activationCode>]\w+, but does not yield the required code. I am a newbie to regular expression and i need help with this.
Can you use look-behind assertion in jmeter? If so, you can use thatr regex which will give you a word that follows <activationCode>
(?<=\<activationCode\>)\w+
If your input string is encoded (e.g for HTML), use:
(?<=\<activationCode\>)\w+
When designing a regular expression in any language for something like this you can match your input string as three groups: (the opening tag, the content, and the closing tag) then select the content from the second group.

Erlang regular expression must match entire string

I am trying to write some code to validate a list of colon separated k/v pairs in erlang. I can get the following expression to match a single pair.
re:run(Tag, "^([a-zA-Z0-9]{1,50}:[^:][ ]?[a-zA-Z0-9\\.\\-\\_\\+]{1,50})")
So, if I pass a tag of key:value it matches as expected. But, I need it to NOT match if I pass something like key:value:123. It appears that what is happening is that re returns {match, Match} if any part of the string matches. However, I need it to only return match if the ENTIRE string matches. Is there a way to do this in erlang? I read-over the docs at http://www.erlang.org/doc/man/re.html and tried a few things with options but have yet to figure it out.
Just add a $ on the end to match the full line:
^([a-zA-Z0-9]{1,50}:[^:][ ]?[a-zA-Z0-9\.\-\_\+]{1,50})$
^ here
This is a feature of regular expressions, not Erlang specifically.

How can I write a regular expression match for a string that must contain the following characters: thankYou.sjs?donate_page

I need to create a regex query for a Google Analytics goal. The goal url must contain:
thankYou.sjs?donate_page
However, there are many urls than can render this string, all with other modifiers that I don't care about.
Please advise.
#ExplosionPills: I think you forgot about the special meaning of the question mark.
If you don't escape it, your expression:
^thankYou.sjs?donate_path$
Would match
thankYou.sjsdonate_path
or
thankYou.sjdonate_path
Not to mention the special meaning of dot.
So I guess something like this should work:
thankYou\.sjs\?donate_path
Furthermore if it's possible that the donate_path is not the first in the query string you can use this:
thankYou\.sjs\?([^&]*&)*donate_path
Just the string itself will work. If you want only this string, just use the start/end of string zero-width assertions:
^thankYou\.sjs\?donate_path$

How do I get the following regular expression to not allow blank e-mails?

I am using the following regular expression to validate e-mails, but it allows empty strings as well, how can I change it to prevent it:
^[\w\.\-]+#[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$
I am using an asp:RegularExpressionValidator. My other option is to add on a asp:RequiredFieldValidator, but I am curious if this is possible to check for blanks in my RegularExpressionValidator, so I don't have to have 2
see http://www.regular-expressions.info/email.html
That expression does not match empty strings. The expression starts with ^[\w\.\-]+ this translates to "The string must start with a word character, period or slash. There can be more than one of these." There must be something else wrong or you copied the expression incorrectly.
This RegEx validates if a given string is in a valid email-format or not:
/^[a-zA-Z0-9\_\-\.]+\#([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/