I'm working on Azure App Insights, how do i Trim a string value ?
For Example: I have the customeDimension value for prop_Message as "Question: This is StackOverflow: Yes"
I want to trim everything before Yes and my result set should be "Yes"
Any suggestion?
I tried Trim() and Split(), Trim() requires a set of predefined string to be replaced and Split() just removes everything on the character count. In my case, the character count differs little bit.
you could try something like this:
datatable(customDimension:dynamic)
[
dynamic({"prop_Message":"Question: This is StackOverflow: Yes"})
]
| parse customDimension.prop_Message with "Question:" * ":" result
Related
I just cannot get this working. i want to subset all the rows containing "mail". I use this:
Email <- subset(Total_Content, source == ".*mail.*")
I have rows like this ones:
"snt152.mail.live.com",
"mailing.serviciosmovistar.com",
"blu179.mail.live.com"
But when using: "View(Email)"
I just get a data.frame empty (just see the columns). I don't need to "scape" any metacharacter, because i need the "." to mean "anycharacter" and the "*" (0 or more times), right? Thanks.
Well, no, it doesn't - it's not meant to. You're not passing it a regular expression to be evaluated against each row, you're just passing it a character string; it doesn't know that . and * are regex characters because it's not performing a regex search. It's returning all rows where source is the literal string .mail. - which in this case is 0 rows.
What you probably want to be doing (I'm assuming this is a data.frame, here) is:
Email <- Total_Content[grepl(x = Total_Content$source, pattern = ".*mail.*"),]
grepl produces a set of boolean values of whether each entry in Total_Content$source matched the pattern. Total_Content[boolean_vector,] limits to those rows of Total_Content where the equivalent boolean is TRUE.
Why not use subset with a logical regex funtion?
Email <- subset(Total_Content, grepl(".*mail.*", source) )
The subset function does create a local environment for the evaluation of expressions that are used in either the 'subset' (row targets) or the 'select' (column targets) arguments.
I'm writing a test case in robot framework. I'm getting the response in below json string:
{"responseTimeStamp":"1970-01-01T05:30:00",
"statusCode":"200",
"statusMsg":"200",
"_object":{"id":"TS82",
"name":"newgroup",
"desc":"ttesteste",
"parentGroups":[],
"childGroups":[],
"devices":null,
"mos":null,
"groupConfigRules" {
"version":null,
"ruleContents":null
},
"applications":null,"type":0
}
}
From that I want to take "_object" using:
${reqresstr} = ${response['_object']}
... but am getting the error "No keyword with name '=' found" error
If I try the following:
${reqresstr}= ${response['_object']}
... I'm getting the error "Keyword name cannot be empty." I tried removing the '=' but still get the same error.
How can I extract '_object' from that json string?
When using the "=" for variable assignment with the space-separated format, you must make sure you have no more than a single space before the "=". Your first example shows that you've got more than one space on either side of the "=". You must have only a single space before the = and two or more after, or robot will think the spaces are a separator between a keyword and argument.
For the "keyword must not be empty" error, the first cell after a variable name must be a keyword. Unlike traditional programming languages, you cannot directly assign a string to a variable.
To set a variable to a string you need to use the Set Variable keyword (or one of the variations such as Set Test Variable). For example:
${reqresstr}= Set variable ${response['_object']}
${reqresstr}= '${response["_object"]}'
wrap it inside quotes and two spaces after =
There is a syntax error in your command. Make sure there is a space between ${reqresstr} and =.
Using your example above:
${reqresstr} = ${response['_object']}
I need to index all the rows that have a string beginning with either "B-" or "B^" in one of the columns. I tried a bunch of combinations, but I am suspecting it might not be working due to "-" and "^" signs being part of grep command as well.
dataset[grep('^(B-|B^)[^B-|B^]*$', dataset$Col1),]
With the above script, rows beginning with "B^" are not being extracted. Please suggest a smart way to handle this.
You can use the escape \\ command in grep:
dataset[grep('^(B\\-|B\\^)[^B\\-|B\\^]*$', dataset$Col1),]
For further explanation, the ^ matches the beginning of a string as an anchor therefore you have to escape it in the middle of string. The [] are a character class so [^B-|B^]* matches any character that's not a B,-,B, or ^. They are unnecessary here.
The simplified regex is:
dataset[grep('^(B-|B\\^)', dataset$Col1),]
I checked different posts on this, but still couldn't figure out why this is not working:
c=c("HI","NO","YESS")
grep("YES",c,fixed=T)
[1] 3
If I am using fixed = T, why I am still getting a results when there is no exact match for "YES". I want only exact matches like when I use grep -w in bash.
This just means that you're matching a string rather than a regular expression, but the string can still be a substring. If you want to match exact cases only, how about
> x=c("HI","NO","YESS") #better not to name variables after common functions
> grep("^YES$",x,fixed=F)
integer(0)
Edit per #nicola: This works b/c ^ means beginning and $ end of string, so ^xxxx$ forces the entire string to match xxxx.
Hi ive got this regular expression and that extracts numbers from a string
string.Join(null,System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
so eg, the format of my string is like this strA:12, strB:14, strC:15
so the regex returns 121415
how can I modify the expression to return
12,14,15 instead, any suggestions please
You're calling String.Join, which joins an array of strings into a single string, separating each element by the separator parameter.
Since you're passing null as that parameter, it doesn't put anything between the strings.
You need to pass ", " instead of null to separate each string with ,.