I have a string and want to find the second match:
string
function (typt,tyu,tyui) {
return artigos.crudButtons(true, true, true);
}
regExpx
\(([^)]+)\)
The result is
[
"(typt,tyu,tyui)",
"typt,tyu,tyui"
]
but i need
[
"(true, true, true)",
"true, true, true"
]
I need to ignore first ocurrence or find after crudButtons.
Thanks in advance
You can find the data after crudButtons as
regex.exec(text.slice(text.indexOf('crudButtons')))
Related
I use a GeoJSON as my source, where every entity has a state.
I want to draw circles for every entity, where the circle color is based on the state, and whether the circle has been clicked or not.
Determining the "clicked-state" is done via setFeatureState() where a feature receives the "click" state when clicked.
I tried to first check for the click state and match the state, based on the feature being clicked or not:
"circle-color": [
'case',
['boolean',
['feature-state', 'click'],
false,
],
['match', //Feature clicked = true
['get', 'state'],
'SOME_FEATURE_STATE_STRING',
'#57E757', // possible match
'SOME_OTHER_FEATURE_STATE_STRING',
'#123456', // possible match
'#123456' //fallback
],
'#001ebe' //Feature clicked = false
]
The "unclicked" circle has the correct color. However, when I click the circle, the circle-color is changed to black and not my "match" color.
Any advice is greatly appreciated!
I think your case expression is incorrect here :
['boolean',
['feature-state', 'click'],
false,
],
You have used the boolean types expression, which is a type expression (it asserts that the input value is a boolean).
In your case, you want to use a decision expression.
With the == operator, you can return true if the input values are equal, false otherwise.
Your case expression would become :
"circle-color": [
'case',
['==', ['feature-state', 'click'], true],
['match', // Feature clicked = true
['get', 'state'],
'SOME_FEATURE_STATE_STRING',
'#57E757', // Possible match
'SOME_OTHER_FEATURE_STATE_STRING',
'#123456', // Possible match
'#123456' // Fallback
],
'#001ebe' // Feature clicked = false
]
I have data structure as below
{
status: false,
executed: true,
output : "Service is under maintenance [ {"command" :"uptime", "output" :"connection timeout"}] - exit status 3
}
I am trying to extract [ { "command" :"uptime", "output" :"connection timeout" }] from above data structure. if it is clean it be using regular dot walking with parse.
As this is not in proper format, I am looking for suggestions only to extract valid data structure.
Any suggestions greatly appreciated.
Thank you.
use indexOf("[") and lastIndexOf("]") to substring the string then use JSON.parse to parse the jsonstring ,then you will get [ { "command" :"uptime", "output" :"connection timeout" }];
hope it would help you
You can use string split functions in JavaScript to split the output string and then Parse the JSON String as a valid JSON. Hope the below code will help you.
var inputJson ={
status: false,
executed: true,
output : 'Service is under maintenance [ {"command" :"uptime", "output" :"connection timeout"}] - exit status 3'
}
var outputJson = JSON.parse(inputJson.output.split("[")[1].split("]")[0]);
console.log(outputJson.output);
Assuming output is a string from Service to status 3...
Here is a function to "clean" your data. I added a condition in case the data isn't "messed" ;)
let messedData = {
status: false,
executed: true,
output: 'Service is under maintenance[{"command": "uptime","output": "connection timeout"}] - exit status 3 '
}
function clean(data){
if(typeof(data.output) === "string"){
data.output = JSON.parse(data.output.match(/\[.+\]/)[0])
}
return data
}
console.log(clean(messedData))
does anybody know how to filter mongodb db.adminCommand output? Because if I run this command db.adminCommand({ "currentOp": true, "op" : "query", "planSummary": "COLLSCAN" }) I get a huge JSON output but I'm only interested in some fields ( like secs_running, op, command, $db)
Many thanks!
You can add the filters straight to the command object like the following:
var commandObj = {
"currentOp" : 1,
"waitingForLock" : true,
"$or" : [
{
"op" : {
"$in" : [
"insert",
"update",
"remove"
]
}
},
{
"command.findandmodify" : {
"$exists" : true
}
}
]
};
db.adminCommand(commandObj);
You can see some filter examples on the MongoDB docs: https://docs.mongodb.com/manual/reference/method/db.currentOp/#examples
Just re-read your question and I think you might of meant just projecting fields back from the database that you care about? if that's the case you can just execute a map on top of the current results so you only see what you care about?
db.adminCommand(commandObj).inprog.map(x => x.opid};
I have a problem with parsing an XML file.
I want to remove strings with characters like \t\n.
XML File: http://ftp.thinkimmo.com/home/immoanzeigen24/immo.xml
{
trim: true,
normalize: true,
attrValueProcessors: [cleanValue, name => name],
valueProcessors: [cleanValue, name => name]
}
cleanValue:
const cleanValue = value => {
return value.toString().trim().replace("\t","atest");
};
I tried cleaning it with a lot of regex I've found online - but value always stays like following:
"verwaltung_objekt": {
"objektadresse_freigeben": "0",
"verfuegbar_ab": "nachaasjkdhkjshadjkashdAbsprache",
"bisdatum": "2016-01-15",
"min_mietdauer": "\n\t\t\t\t",
"max_mietdauer": "\n\t\t\t\t",
}
This is a difficult one!
I'd suggest following a simple strategy and pre-processing the xml data before you parse it.
This should resolve your issue at least.
If you just do something like:
function trimXml(xml) {
return xml.replace(/>\s+</g, "><");
}
xml = trimXml(xml);
Then parse the trimmed xml data. You should see the output now looks like so:
"verwaltung_objekt": [
{
"objektadresse_freigeben": [
"1"
],
"abdatum": [
"2017-03-01"
],
"min_mietdauer": [
""
],
"max_mietdauer": [
""
]
}
],
Which is a bit more like what you want!
I have a Dynamoose (DynamoDB) model called PromoCode with a schema that looks like this:
{
promoCode: {
hashKey: true,
type: String,
},
previouslyUsed: {
type: Boolean,
default: false,
index: {
global: true,
name: 'previouslyUsedIndex',
},
},
promoGroup: {
type: String,
index: {
global: true,
name: 'promoGroupIndex',
},
},
}
Essentially, I have a table full of promo codes and I want to get a single promo code that hasn't been used and is part of a particular "group" of promo codes.
So, I want to query on both previouslyUsed and promoGroup fields and limit the results to a single results. This is what I came up with:
PromoCode.query('previouslyUsed').eq(false)
.and()
.filter('promoGroup').eq('friend').limit(1)
This returns no results, even though I know that the query should match a result. If I increase the limit to 10, then I get back four results. This makes me think that the limit is happenning before the and() thus the preceding filter() is only filtering on the 10 returned results where previouslyUsed=false.
How do I take a single result where the conditions previouslyUsed=false and promoGroup=friend are valid?
So, here's what I figured out (to answer my own question). Firstly, using filter will only filter the results that are pulled from the database. So, I wasn't experiencing some weird bug.
Secondly, what I really wanted was a range key setup. This will give me the following schema:
{
promoCode: {
hashKey: true,
type: String,
},
previouslyUsed: {
type: Boolean,
default: false,
index: {
global: true,
name: 'previouslyUsedIndex',
rangeKey: 'promoGroup',
},
},
promoGroup: {
type: String,
rangeKey: true,
index: true,
},
}
Note the use of both instances of rangeKey above. Evidently both are necessary to do the following query:
PromoCode.query('previouslyUsed').eq(false)
.where('promoGroup').eq('friend')
It's actually as "simple" as that. This let's me filter on two different fields.