I need to pass through queryParams in wireMock
Person=[{age=6,name=AAA}]
I've been getting 404 when I test in the curl request. Aly leads would be appreciated.
Only thing i know is
"Person": {
"matches": "^[a-zA-Z0-9_-]*$"
}
I'm not sure on how to validate the array.
Your regex matching is incorrect. The value of Person is [{age=6,name=AAA}], so your matcher will need to capture all of that to be considered a match. You've used some special characters that need escaping, as well as an invalid capture group (which I don't think we really need here.) Without any more guidance from your post on what you precisely need to match, here's two rough ideas:
"Person": {
"matches": "^\[.*\]$"
}
The above just matches any character, an unlimited amount of times, between brackets.
"Person": {
"matches": "^\[\{age=\d*,name=\w*\}\]$"
}
The above matches any digit character, an unlimited amount of times, as well as any word character, an unlimited amount of times, so long as the rest of the value looks like [{age=,name=}].
I would advise you to take a look at a regex tool to work on forming these. My personal favorite is regex101.
Related
Hi I have a field in a user collection called "Address".User saving their address from a textarea in my application. mongodb convert it to new line like following.
{
"_id": ObjectId("56a9ba0ffbe0856d4f8b456d"),
"address": "HOUSE NO. 3157,\r\nSECTOR 50-D",
"pincode": "",
},
{
"_id": ObjectId("56a9ba0ffbe0856d4f8b456d"),
"address": "HOUSE NO. 3257,\r\nSECTOR 50-C",
"pincode": "",
}
So now When I am running a search query on the basis of "address".Like following:
guardianAdd = $dm->getRepository('EduStudentBundle:GuardianAddress')->findBy(array(
'address' => new \MongoRegex('/.*' .$data['address'] . '.*/i'),
'isDelete' => false
));
echo count($guardianAdd);die;
it does not give any result. My Searchi key word is : "HOUSE NO.3157 SECTOR 50-D".
However if I am searching using like: HOUSE NO. 3157 its giving correct result.
Please advice how to fix this.Thanks in advance
First of all, trailing .* are redundant. regexps /.*aaa.*/ and /aaa/ are identical and match the same pattern.
Second, you probably need to use multiline modifier /pattern/im
Finally, it is not quite clear what you want to fix. The best think you can do is to provide some basic explanation of regex syntax in the search form, so users can search properly, e.g. HOUSE NO.*3157.*SECTOR 50-D to get best results.
You can make some bold assumptions and build the pattern with something like
$pattern = implode('\W+',preg_split('/\W+/', $data['address']))
which will give you a regexp HOUSE\W+NO\W+3157\W+SECTOR\W+50\W+D for different kind of HOUSE NO.3157 SECTOR 50-D requests, but it will cut all the regex flexibility available with bare input, and eventually will result with unexpected response anyway. You can follow this slippery slope and end up with your own query DSL to compile to regex, but I doubt it can be any better or more convenient than pure regex. It will be more error prone for sure.
Asking right question to get right answers is true not only on SO, but also in your application. Unfortunately there is no general solution to search for something that people have in mind, but fail to ask. I believe that in your particular case best code is no code.
I have a content like:
"emailAddress":"akashu87#gmail.com","UserName":"Akash Udupa","active":true,"emailAddress":"coolrohit#rediffmail.com","UserName":"Rohit Hegde","active":true,"emailAddress":"manohar_k#rediffmail.com","UserName":"Manohar Karnam","active":true,"emailAddress":"satishgk#hotmail.com","UserName":"Satish GK","active":true
I want to display only the values of UserName in CSV file through PERL like the following:
Akash Udupa
Rohit Hegde
Manohar Karnam
Satish GK
I am sure you guys will ask me what I have tried. Problem is I am very new to PERL. So can anyone help me with perl code? Please.
Thanks in advance.
There are two ways to do this; the right way, and the fragile way. Since your JSON has its braces and brackets stripped away, you've already started down the path to the fragile way:
my $string = q{"emailAddress":"akashu87#gmail.com","UserName":"Akash Udupa","active":true,"emailAddress":"coolrohit#rediffmail.com","UserName":"Rohit Hegde","active":true,"emailAddress":"manohar_k#rediffmail.com","UserName":"Manohar Karnam","active":true,"emailAddress":"satishgk#hotmail.com","UserName":"Satish GK","active":true};
while ( $string =~ m/"UserName"\s*:\s*"([^"]+)"/g ) {
print "$1\n";
}
This anchors to the "UserName" tag, and allows whitespace (but does not require it) between the tag and its value. It then looks for a double-quote, and captures everything until the next quote into $1.
A brief introduction to Perl's regexes is contained in perlrequick, which comes with Perl. My regex solution doesn't use any constructs not explained in that document. As a matter of fact, perlintro, which should be considered required reading for Perl users, provides information sufficient to this task.
Since it's possible that the logic that stripped away the JSON might have broken something, and since the JSON might possibly throw something at you that our one-off regular expression isn't equipped to handle, it would be wise to revert to the original un-adulterated JSON, and parse it with a proper parser, like this:
use JSON;
my $json = <<'EOJSON';
[
{
"emailAddress": "akashu87#gmail.com",
"UserName": "AkashUdupa",
"active": true
},
{
"emailAddress": "coolrohit#rediffmail.com",
"UserName": "RohitHegde",
"active": true
},
{
"emailAddress": "manohar_k#rediffmail.com",
"UserName": "ManoharKarnam",
"active": true
},
{
"emailAddress": "satishgk#hotmail.com",
"UserName": "SatishGK",
"active": true
}
]
EOJSON
print "$_->{UserName}\n" for #{decode_json($json)}
If the JSON module is too heavy-weight for you, look at JSON::Tiny, which is minimal, well tested, and free of dependencies.
Both the regex and the parser approach will work with the original JSON, so you may find that your code can be simplified by just eliminating the section that strips brackets and braces from the original JSON. Once you've done that, the JSON parser solution can be one line of code. It's a lucky day when removing code can make the code more robust without removing features.
I have this data in one column in postgresql
{
"geometry":{
"status":"Point",
"coordinates":[
-122.421583,
37.795027
]
},
and i using his query
select * from students where data_json LIKE '%status%' ;
Above query return results but this one does not
select * from students where data_json LIKE '%status:%' ;
How can fix that
Of course the 2nd one doesn't find a match, there's no status: text in the value. I think you wanted:
select * from students where data_json LIKE '%"status":%'
... however, like most cases where you attempt text pattern matching on structured data this is in general a terrible idea that will bite you. Just a couple of problem examples:
{
"somekey": "the value is \"status\": true"
}
... where "status": appears as part of the text value and will match even though it shouldn't, and:
{
status : "blah"
}
where status has no quotes and a space between the quotes and colon. As far as JavaScript is concerned this is the same as "status": but it won't match.
If you're trying to find fields within json or extract fields from json, do it with a json parser. PL/V8 may be of interest, or the json libraries available for tools like pl/perl, pl/pythonu, etc. Future PostgreSQL versions will have functions to get a json key by path, test if a json value exists, etc, but 9.2 does not.
At this point you might be thinking "why don't I use regular expressions". Don't go there, you do not want to try to write a full JSON parser in regex. this blog entry is somewhat relevant.
All,
I have a string in a dictionary that's in an array that I need to manipulate a bit. The string returns: TEST-TEST-ABC_Dry_Cleaning-R12-01.
Here's what I need to do with it:
I need to pull out "ABC_Dry_Cleaning" and change it to "ABC Dry Cleaning" (no underscores)
I need to delete "TEST-TEST-"
I need to pull out "R12" and put that in a different string
I need to add "01" on to the end of "ABC Dry Cleaning" (looks like "ABC Dry Cleaning (01)")
How would I do these general things? There is much more that needs to be done, but once I know the way to do these tasks I can change it around for the others as needed. NOTE: "ABC_Dry_Cleaning" could be just "Red_Cups" or "McDonalds_Bag" - basically, a count of characters won't work.
Thanks!
If you're on iOS4+, consider using a regular expression to match the segments that you're interested in retaining. Take a look at the NSRegularExpression class.
You can then use the matches to build up the final string.
Sql query:
select * from test_mart
where replace(replace(replace(replace(replace(replace(lower(name),'+'),'_'),'the '),' the'),'a '),' a')='tariq'
I can fire following query very easy, if I have to use simply Sqlite... but In current project I am using Core Data so not familiar about NSPredicate much.
The functionality talks about removing all BUT alphanumeric characters, which means removing special characters.
The characters that should be valid in the comparison would be
ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890
But we should not fail the comparison for the following characters
:;,~`!##$%^&*()_-+="'/?.>,<|\
Or for the following words
'the' 'an' 'a'
Some examples:
'Walmart' would be seen as the same payee as 'Wal-Mart'
'The Shoe Store' would be seen as the same payee as 'Shoe Store'
'Domino's Pizza' would be seen as the same payee as 'Dominos Pizza'
'Test Payee;' would be seen as the same payee as 'Test Payee'
Can any one suggest appropriate Predicates/Regular Expression ?
Thanks
I would have an extra field in the data base which would be a processed version of the original with all the irrelevant characters stripped out. Then use that for comparisons.
You might want to look at the soundex algorithm which may suite your purposes better... Soundex
It seems to me that you would want to normalize your data before it every gets set into the core data store. So if you're given "Wal-Mart", normalize it to "walmart" once, and then save it. Then you won't be doing all of this expensive on-the-fly comparison many many times.
The normalization would be fairly simple, given your rules:
Strip the words "a", "an", and "the"
Remove punctuation