Regex with SpEl usage - regex

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}' + '.*'}"

Related

How can I fix this error in my go project - undefined: bson.RegEx

I get the following error from my editor:
undefined: bson.RegEx
due to this line of code in my go project:
regex := bson.M{"$regex": bson.RegEx{Pattern: id, Options: "i"}}
Why am I getting this error and how can I resolve it?
I've made sure that I'm importing:
"go.mongdb.org/mongo-driver/bson"
I've also checked inside bson/primitive/primitive.go to see that RegEx does exist
Using version 1.1.0 of mongo-driver.
Managed to work around the problem by removing this:
regex := bson.M{"$regex": bson.RegEx{Pattern: id, Options: "i"}}
and add this instead:
regex := `(?i).*` + name + `.*`
filter = bson.M{"name": bson.M{"$regex": regex}}
Why am I getting this error and how can I resolve it?
Using mongo-go-driver v1+, you can utilise bson.primitive. For example:
patternName := `.*` + name + `.*`
filter := bson.M{"name": primitive.Regex{Pattern: patternName, Options:"i"}}
cursor, err := collection.Find(context.TODO(), filter)
This is imported from "go.mongodb.org/mongo-driver/bson/primitive".
In addition, I would also suggest to consider the search pattern. You can optimise a regex search if the regular expression is a “prefix expression”, which means that all potential matches start with the same string. For example, ^name.* will be optimised by matching only against the values from the index that starts with name.
Also worth noting that case insensitive regular expression queries generally cannot use indexes effectively. The $regex implementation is not collation-aware and is unable to utilise case-insensitive indexes. Please see $regex index use for more information.
Depending on the use case, consider MongoDB Text Search. For example, you can create a text index:
db.collection.createIndex({"name":"text"});
Which then you can search using:
filter := bson.M{"$text": bson.M{"$search": name}}
cur, err := collection.Find(context.TODO(), filter)
Also worth mentioning depending on your requirements, there's also MongoDB Atlas Full Text Search feature for advanced search functionality. i.e. text analysers.

paste split pattern for ngx-chips (Angular)

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]"

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 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)

How to use Regexp to retrieve URL where link text has number in the bracket

I want to retrieve all links from the page, where link text is in the below format.
(10) Now I tried using below method but it didn't work.
There are many similar links available on the same page where number is not in sequence and also there are many repeated numbers for the link text, so I want to first collect such web element and then using attribute I can get the URL.
Similar to this page.
http://www.dmoz.org/search?q=surat&start=0&type=more&all=no&cat=
I want the link after we click on those numbers present in the bracket.
List<WebElement> catLinks = driver.findElements(By.xpath("//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[1]/a[2]"));
for (WebElement catLink : catLinks) {
System.out.println(nLink + ". " + catLink.getAttribute("href"));
}
Link XPath is:
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[***1***]/a[2]
Using Above XPath I can get the first link URL. Now What I can do to get all links URL.
I tried using regexp :
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[\\d\\.\\*]/a[2]
But it is not working.
I also tried using below method.
List<WebElement> catLinks = driver.findElements(By.linkText("\\d\.\*"));
for (WebElement catLink : catLinks) {
System.out.println(nLink + ". " + catLink.getAttribute("href"));
}
but no luck.
Now What I can do to get all links
URL.
I triedn using regex :
//html/body/div[#id='doc']/div[#id='bd-cross']/ol/li[\\d\\.\\*]/a[2]
Nop. Use:
/html/body/div[#id='doc']/div[#id='bd-cross']/ol/li/a[2]
Less is more.
You don't need to include the /html/body/ in the xpath locator, this will just make it more fragile if the page structure changes. Try this much simpler xpath locator: id('bd-cross')//li/a[2]