paste split pattern for ngx-chips (Angular) - regex

I'm trying to allow users to paste a list that is separated by , ; or | using ngx-chips.
There is an option to do this with pasteSplitPattern - [?string | RegExp]
https://github.com/Gbuomprisco/ngx-chips
When I try the following though, I get an error
[pasteSplitPattern]="[,|;]"
Parser Error: Unexpected token ,
What should I be doing differently?

Try using the following:
Define a new regex :
splitPattern = new RegExp('[\,\;]');
and then use it in your template:
[pasteSplitPattern]= "splitPattern"

I had the same problem : you have to add [addOnPaste]="true" to make it work!

use the below to separate by comma or enter
[separatorKeyCodes]="[32, 188]"

Related

Wiremock withQueryParam not matching regex

I'm trying to do this:
stubFor(get("/my/path")
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
and I get this error:
GET | GET
/my/path | /my/path?paramName=v1Value <<<<< URL does not match
|
Query: paramName [matches] ^(v1Value)|(v2Value)|(v3Value)$ | paramName: v1Value
I have tested the regex and it works. I also debugged and I saw that the RegexPattern also matches. But for some reason, I still get this error. I believe I'm using it wrongly.
I tried a simpler version that also didn't work:
stubFor(get("/my/path")
.withQueryParam("paramName", equalTo("v1Value"))
.willReturn(okJson(RESPONSE)));
Any ideas? Thanks in advance.
WireMock documentation recommends matching on url path only and matching on query parameters separately.
That would look something like...
stubFor(get(urlPathEqualTo("/my/path"))
.withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
.willReturn(okJson(RESPONSE)));
If I recall correctly, just using stubFor(get("my/url")) defaults to using urlEqualTo, which checks equality matching on path and query parameters

RegEx to normalize XML syntax

I have an XML-code where some tags generate xml parse errors (Error #1090). The problem is in attributes that need to be quoted:
<div class=treeview>
Help me please to write a regular expression to make them as following:
<div class="treeview">
this one will be correct:
var pattern:RegExp = /(\w+)(=)(\w+)/g;
trace('regexTest:', pString.replace(pattern, '$1$2"$3"'));
because, there must be 3 groups: attribute_name, = (equals), attribute_value
Please, could you try the next code:
var regExp:RegExp = /(class\=)(\w+)/g;
var sourceText:String = "<div class=treeview>";
var replacedText:String = sourceText.replace(regExp, '$1"$2"');
trace(replacedText);
In a nutshell, this RegExp means:
Find 2 groups: (class=) and (any-word-after-it)
Add before and after the group 2 quotes.
You should try the following regex>
regex = /(<div[^>]*class=)(\S+)([^>]*>)/g;
sourceString.replace(regex, '$1"$2"$3');
Try using a general purpose markup repair tool such as John Cowan's TagSoup. This is likely to be much more robust than anything you attempt yourself (for example, most of the suggested regular expressions don't even check that the keyword=value construct is within a start tag).

Regex with SpEl usage

How to use regex with SpEL?
Would like to append system properties along with SpEL and regex .
expected output : devInmessagebase/devInmessagetest/devInmessagesample
dev :'env' variable
Inmessage : from properties file(in.topic.mesge)
asterisk(*) : base/test/sample(anything as suffix)
Tried as below and many other ways but not working.any suggestion?
<int-kafka:consumer-configuration group-id="default3" value-decoder="kafkaSpecificDecoder"
key-decoder="kafkaReflectionDecoder" max-messages="10">
<int-kafka:topic-filter pattern="${systemProperties['env'] + in.topic.mesge.'*'}" streams="4" exclude="false" /> </int-kafka:consumer-configuration>
The correct syntax for the pattern attribute is:
pattern="#{systemProperties['env'] + '${in.topic.mesge}' + '.*'}"

Regex JSON response Gatling stress tool

Wanting to capture a variable called scanNumber in the http response loking like this:
{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}
How can I do this with a regular experssion?
The tool I am using is Gatling stress tool (with the Scala DSL)
I have tried to do it like this:
.check(jsonPath("""${scanNumber}""").saveAs("scanNr")))
But I get the error:
---- Errors --------------------------------------------------------------------
> Check extractor resolution crashed: No attribute named 'scanNu 5 (100,0%)
mber' is defined
You were close first time.
What you actually want is:
.check(jsonPath("""$..scanNumber""").saveAs("scanNr")))
or possibly:
.check(jsonPath("""$.profile.memberships[0].scanNumber""").saveAs("scanNr")))
Note that this uses jsonPath, not regular expressions. JsonPath should more reliable than regex for this.
Check out the JsonPath spec for more advanced usage.
use this regex to match this in anywhere in json:
/"scanNumber":"[^"]+"/
and if you want to match just happens in structure you said use:
/\{[^{[]+\{[^{[]+\[\{[^{[]*("scanNumber":"[^"]+")/
Since json fields may change its order you should make your regex more tolerant for those changes:
val j = """{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}"""
val scanNumberRegx = """\{.*"memberships":\[\{.*"scanNumber":"([^"]*)".*""".r
val scanNumberRegx(scanNumber) = j
scanNumber //String = 123-456-123-123
This will work even if the json fields will be in different order (but of course keep the structure)

error with RegExp inside angular.toJson

I'm trying to do a 'like' query in mongodb. I see that's done with a regexp so I'm trying to set it like this:
$scope.clients = Client.query({
q:angular.toJson({
name: RegExp($routeParams.str)
})
});
The thing is angular.toJson function does not get any regexp:
http://plnkr.co/edit/idXMT1
Is there any other way to do that?
From my understanding of your question, you want your JSON object to contain the regular expression as a string?
In that case, you can manually convert it to a string in the declaration, i.e:
$scope.object = angular.toJson({
"param" : new RegExp(str).toString()
});
See updated plunk:
http://plnkr.co/edit/yLogI8
I finally found a solution.
The problem is using the toJon function as it does not allow any key starting with / or $ so the solution is avoiding the use of this function and just write the object as a string
$scope.clients = Client.query({
q:'{src:{$regex:"' + $routeParams.str + '"}}'
};