When using firebase with functions it is possible to use regular expressions to match incoming requests and based on the match use a specific function sharing the same endpoint? for example, I am trying this:
{
"hosting": {
"rewrites": [
{
"source": "/^([0-9a-f]{2}[:-]){15}([0-9a-f]{2})$",
"function": "getFingerprint"
},
{
"source": "/*",
"function": "callNew"
}
]
}
}
I would like to match urls like:
http://test.firebaseapp.com/b4:e8:b4:ec:4a:36:76:4b:04:4a:83:c9:47:d4:c8:70
If the request matches the defined regular expression then use the function getFingerprint if not, in my try to implement a "catch-all", I am using /*.
The only pattern that works at the moment is /*, but can't find a way to make this one to work:
^([0-9a-f]{2}[:-]){15}([0-9a-f]{2})$
Therefore wondering if is possible to use any regex within the firebase.json file for configuring custom rewrites and share endpoints, for example, / in this case or as an alternative better to have a unique resource and then split the URL path to retrieve the paths as parameters
From the documentation on Firebase Hosting rewrite rules:
A source specifying a glob pattern
Glob patterns are a subset of regular expressions, and for example I don't it supports the ^ and $ terminator expressions that you use.
Related
My goal is to redirect any URL that does not start with a specific symbol ("#") to a different website.
I am using Firebase Hosting and already tried the Regex function in redirect to achieve this. I followed this firebase documentation on redirects but because I new to regular expressions I assume that my mistake might be my regex code.
My Goal:
mydomain.com/anyNotStartingWith# => otherdomain.com/anyNotStartingWith#
mydomain.com/#any => mydomain.com/#any
My Code:
{
"hosting": {
...
"redirects": [
{
"regex": "/^[^#]:params*",
"destination": "otherdomain.com/:params",
"type": 301
}
],
...
}
}
You can use
"regex": "/(?P<params>[^/#].*)"
The point is that you need a capturing group that will match and capture the part you want to use in the destination. So, in this case
/ - matches /
(?P<params>[^/#].*) - Named capturing group params (you can refer to the group from the destination using :params):
[^/#] - any char other than / and #
.* - any zero or more chars other than line break chars, as many as possible
To avoid matching files with .js, you can use
/(?P<params>[^/#].*(?:[^.].{2}$|.[^j].$|.{2}[^s]$))$
See this RE2 regex demo
See more about how to negate patterns at Regex: match everything but specific pattern.
I have a link like http://drive.google.com and I want to match "google" out of the link.
I have:
query: {
bool : {
must: {
match: { text: 'google'}
}
}
}
But this only matches if the whole text is 'google' (case insensitive, so it also matches Google or GooGlE etc). How do I match for the 'google' inside of another string?
The point is that the ElasticSearch regex you are using requires a full string match:
Lucene’s patterns are always anchored. The pattern provided must match the entire string.
Thus, to match any character (but a newline), you can use .* pattern:
match: { text: '.*google.*'}
^^ ^^
In ES6+, use regexp insted of match:
"query": {
"regexp": { "text": ".*google.*"}
}
One more variation is for cases when your string can have newlines: match: { text: '(.|\n)*google(.|\n)*'}. This awful (.|\n)* is a must in ElasticSearch because this regex flavor does not allow any [\s\S] workarounds, nor any DOTALL/Singleline flags. "The Lucene regular expression engine is not Perl-compatible but supports a smaller range of operators."
However, if you do not plan to match any complicated patterns and need no word boundary checking, regex search for a mere substring is better performed with a mere wildcard search:
{
"query": {
"wildcard": {
"text": {
"value": "*google*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
See Wildcard search for more details.
NOTE: The wildcard pattern also needs to match the whole input string, thus
google* finds all strings starting with google
*google* finds all strings containing google
*google finds all strings ending with google
Also, bear in mind the only pair of special characters in wildcard patterns:
?, which matches any single character
*, which can match zero or more characters, including an empty one
use wildcard query:
'{"query":{ "wildcard": { "text.keyword" : "*google*" }}}'
For both partial and full text matching ,the following worked
"query" : {
"query_string" : {
"query" : "*searchText*",
"fields" : [
"fieldName"
]
}
I can't find a breaking change disabling regular expressions in match, but match: { text: '.*google.*'} does not work on any of my Elasticsearch 6.2 clusters. Perhaps it is configurable?
Regexp works:
"query": {
"regexp": { "text": ".*google.*"}
}
For partial matching you can either use prefix or match_phrase_prefix.
For a more generic solution you can look into using a different analyzer or defining your own. I am assuming you are using the standard analyzer which would split http://drive.google.com into the tokens "http" and "drive.google.com". This is why the search for just google isn't working because it is trying to compare it to the full "drive.google.com".
If instead you indexed your documents using the simple analyzer it would split it up into "http", "drive", "google", and "com". This will allow you to match anyone of those terms on their own.
using node.js client
tag_name is the field name, value is the incoming search value.
const { body } = await elasticWrapper.client.search({
index: ElasticIndexs.Tags,
body: {
query: {
wildcard: {
tag_name: {
value: `*${value}*`,
boost: 1.0,
rewrite: 'constant_score',
},
},
},
},
});
You're looking for a wildcard search. According to the official documentation, it can be done as follows:
query_string: {
query: `*${keyword}*`,
fields: ["fieldOne", "fieldTwo"],
},
Wildcard searches can be run on individual terms, using ? to replace a single character, and * to replace zero or more characters: qu?ck bro*
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-wildcard
Be careful, though:
Be aware that wildcard queries can use an enormous amount of memory and perform very badly — just think how many terms need to be queried to match the query string "a* b* c*".
Allowing a wildcard at the beginning of a word (eg "*ing") is particularly heavy, because all terms in the index need to be examined, just in case they match. Leading wildcards can be disabled by setting allow_leading_wildcard to false.
I have JSON response from which i want to extract the "transaction id" value i.e (3159184) in this case and use it in my next sampler. Can somebody give me regular expression to extract the value for the same. I have looked for some solutions but it doesn't seem to work
{
"lock_release_date": "2021-04-03T16:16:59.7800000+00:00",
"party_id": "13623162",
"reservation_id": "reserve-1-81b70981-f766-4ca7-a423-1f66ecaa7f2b",
"reservation_line_items": [
{
"extended_properties": null,
"inventory_pool": "available",
"lead_type": "Flex",
"line_item_id": "1",
"market_id": 491759,
"market_key": "143278|CA|COBROKE|CITY|FULL",
"market_name": "143278",
"market_state_id": "CA",
"product_name": "Local Expert",
"product_size": "SOV30",
"product_type": "Postal Code",
"reserved_quantity": 0,
"transaction_id": 3159174
}
],
"reserved_by": "user1#abc.com"
}
Here's what i'm trying in Jmeter
If you really want the regular expression it would be something like:
"transaction_id"\s?:\s?(\d+)
Demo:
where:
\s? stands for an optional whitespace - this is why your expression doesn't work
\d+ stands for a number
See Regular Expressions chapter of JMeter User Manual for more details.
Be aware that parsing JSON using regular expressions is not the best idea, consider using JSON Extractor instead. It allows fetching "interesting" values from JSON using simple JsonPath queries which are easier to create/read and they are more robust and reliable. The relevant JSON Path query would be:
$.reservation_line_items[0].transaction_id
More information: API Testing With JMeter and the JSON Extractor
Use JSON Extractor for JSON response rather using Regular Expression extractor.
Use JSON Path Expressions as $..transaction_id
Results:
Simplest Regular Expression for extracting above is:
transaction_id": (.+)
Where:
() is used for creating capture group.
. (dot) matches any character except line breaks.
+ (plus) matches 1 or more of the preceding token.
(.+?) could be used to stop looking after first instance is found.
i.e. ? makes the preceding quantifier lazy, causing it to match as few characters as possible. By default, quantifiers are greedy, and will match as many characters as possible.
I'm trying to implement a firebase security rule to check if it is a valid url by using regex. Here is some sample of the url :
https://firebasestorage.googleapis.com/andTheRestIsJustThePartAfterIUploadedIntoFirebaseStorage
I used this regex to check:
"imageURL": {
".validate": "newData.val().matches(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+#)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%#.\w_]*)#?(?:[\w]*))?)/)"
}
However, I'm getting error at Line 26: Invalid escape: '\+'.
Any ideas?
Its not necessary to escape + in a regex class, instead use this:
[-+=&;%#.\w_]
I see another syntax errors in your pattern, some character should be escaped athors should not, your pattern should look like this :
/((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=+\\$,\\w]+#)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+\\$,\\w]+#)[A-Za-z0-9.-]+)((?:\\/[%+~\\/.\\w-_]*)?\\??(?:[-+=&;%#.\\w_]*)#?(?:[\\w]*))?)/
But i'm not sure of about the logic of your pattern, i could suggest to read this for more information about Firebase Security Rules Regular Expressions
I am having trouble making my chrome extension work with multiple URL's What should be the format for listing URL's to match?
chrome.webNavigation.onDOMContentLoaded.addListener(function (o) {
chrome.tabs.executeScript(o.id, {
code: "////////"
})}, {
url: [
{ urlContains: ['/shop/jacket', 'shop/t-shirt']}
]
});
I'm assuming a regex would work, but how would I write that?
Your code doesn't work because urlContains expects a single string only.
The simplest regex operator that matches "A or B" is A|B.
So, in your case { urlMatches : "/shop/jacket|shop/t-shirt" }. It's simple in your case since your URL substrings do not contain special characters; in the general case you may need to \-escape some characters.