Regular Expression Issue on Model Class - regex

I have a model class with the following property for my country list.
[Required(ErrorMessage = "Please select a country")]
[RegularExpression("^(?!----------------$)", ErrorMessage= "Please select a country")]
public string Country { get; set; }
At the moment when users click on any countries they will get the error message !?
I only need to display the error message when users click on ---------------- option only.
I have already tried couple of other expressions but they seem not work at all.
also tried this : [RegularExpression("/^(?!----------------)$/"
any ideas ?

Use a pattern that matches what is valid of course. Also, do not use opening and closing forward slashes in your pattern.
An easy fix for the pattern you tried is to supplement the negative lookahead with .+:
^(?!----------------).+$
Here is a regex fiddle for the tweaked version of your pattern.
However, I would consider a pattern like the following judging by the countries in your list - and refine it as needed (e.g. for Unicode characters etcetera):
^[A-Z][a-z]+( [A-Z][a-z]+)*( \([A-Z]+\))*$
Here is a regex fiddle for this alternate (starting-point) pattern.

Related

get the complete string in a line excluding the matching regex

For example, if a value matches "an email pattern", then remove the key also associated to it from the url.
If url is
https://stackoverflow.com/?key1=test&key2=test#gmail.com&key3=something&key4=another#email.com,
then remove key2=test#gmail.com and key4=another#email.com, so that the new url will be
https://stackoverflow.com/?key1=test&key3=something
Here, key names are not fixed and they can be anything. and also the position of the keys is not fixed.
So, want a regex to get the entire string which does not contain those key value pairs. I tried to generate the regex to match the unwanted key value pairs, but could get the rest of the string which does not match the regex.
I did it using a java program. But looking at a regex so that I can apply in the xml and avoid a java program
This is mainly to use in urlrewritefilter (tuckey) and want to remove certain query strings matching a regex.
Here is a simple solution in java (I saw your question is tagged as java). This is basically pattern that matches ? or & followed by a word then a = and then an email. You can substitute that part [.\w]+#[\w]+\.\w+ with a better email regex. Finding email with regex can be tricky with stranger emails but this would be the basic idea.
public class HelloWorld{
public static void main(String []args){
String url="https://stackoverflow.com/?key1=test&key2=test#gmail.com&key3=something&key4=another#email.com";
System.out.println(url.replaceAll("[?&]\\w+=[.\\w]+#[\\w]+\\.\\w+",""));
}
}

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.

Kibana query exact match

I would like to know how to query a field to exactly match a string.
I'm actually trying to query like this:
url : "http://www.domain_name.com"
Which returns all string starting with http://www.domain_name.com .
I had a similar issue, and ifound that ".raw" fixed it - in your example, try
url.raw : "http://www.domain_name.com"
Or for newer versions of ES(5.x, 6.x):
url.keyword : "http://www.domain_name.com"
Just giving more visibility to #dezhi's comment.
in newer version of ES(5.x, 6.x),
you should use `url.keyword` instead,
as they have changed to a new keyword type.
Therefore, it would be:
url.keyword : "http://www.domain_name.com"
Exact value is not supported out of the box.
http://blogs.perl.org/users/mark_leighton_fisher/2012/01/stupid-lucene-tricks-exact-match-starts-with-ends-with.html
Out of the box, Lucene does not provide exact field matches, like matching "Acer Negundo Ab" and only "Acer Negundo Ab" (not also "Acer
Negundo Ab IgG" ). Neither does Lucene provide "Starts With" or "Ends
With" functionality. Fortunately, there are workarounds.
"Cannot change the info of a user"
To search for an exact string, you need to wrap the string in double
quotation marks. Without quotation marks, the search in the example
would match any documents containing one of the following words:
"Cannot" OR "change" OR "the" OR "info" OR "a" OR "user".
Kibana v6.5
As per you query, it seems fine.
For matching the exact following is the syntax :
fieldname : string
and
For matchign the Substring, use wild card (*),
Syntax :
fieldname : *string*
Also, whatever the query you applied; is that query is the part of Query Criteria of your particuler output component.
So, i suggest you to check whether any of the wild card is applied in your search.

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.

mvc3 RegularExpression block word

I have a MVC3 model and a textbox that accepts some html it works perfectly, but how can I filter the 2 words www and porn as there are some people that are constantly writing that,my model is
[AllowHtml]
[RegularExpression(#"^([^<]|<em>|</em>|<u>|</u>||a z|A Z|1 9|)*$", ErrorMessage = "Invalid character")]
public string mytextbox { get; set; }
So that above works correctly user's can put in HTML only using em and u . As stated above how can i filter the worlds www and porn . I been looking everywhere but haven't found how to do it..
You could use a negative lookahead, like:
^(?!.*(?:www|porn))(?:[^<>]|<em>|</em>|<u>|</u>)*\z
The rest of your expression was useless, so I removed it. Note that you have to get the encoding right when doing filtering like this. And there could be other ways around it.
It will also match any words which include www or porn. If you don't want that you could add some \bs.