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 ,.
Related
The string is "Some Words(1440)" and I want to store the numbers inside the parenthesis as a variable in twig so it can be output and used. I thought maybe I could do it with a split but I wasn't able to escape the parenthesis properly.
What I have:
Some Words (1440)
What I want to extract from the string is just the numbers in parenthesis
1440
I have a json string that's is a nested dataframe and is full of characters that need to be escaped like \n, \r and \. I have not been able to convert it with jsonlite.
Here's a dput of the first element of the list.
fromJSON(json_data) gives the following error:
Replacing the character "{" with blank character is not working.
Any help would be greatly appreciated.
This solution is meant to be a stop-gap for one known flaw in the json validation: two (or more) dictionaries are not separated by a comma. I discourage the use of regular expressions to fix this, but a fixed string-replacement can suffice:
json_date <- gsub("} {", "},{", json_data, fixed = TRUE)
I have a main string as below
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
From the main string i need to extract a substring starting from the uuid part
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
I tried
string.match("/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/", "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/(.)/(.)/$"
But noluck.
if you want to obtain
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
from
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
or let's say 7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0, output and 9999.317528060546245771146821638997525068657 as this is what your pattern attempt suggests. Otherwise leave out the parenthesis in the following solution.
You can use a pattern like this:
local text = "/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(text:match("/([%x%-]+)/([^/]+)/([^/]+)"))
"/([^/]+)/" captures at least one non-slash-character between two slashs.
On your attempt:
You cannot give counts like {4} in a string pattern.
You have to escape - with % as it is a magic character.
(.) would only capture a single character.
Please read the Lua manual to find out what you did wrong and how to use string patterns properly.
Try also the code
s="/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(s:match("/.-/.-(/.+)$"))
It skips the first two "fields" by using a non-greedy match.
It seems ",", "$", "/" all serve as a separator, but "_" not.
x = "1"
"$x,x", "$x$x", "$x/1", "$x_1"
Is there any doc about this?
I believe this is because x_1 is a valid variable name in Julia, so it is trying to insert the value of that variable into the string.
The doc says:
The shortest complete expression after the $ is taken as the expression whose value is to be interpolated into the string
The internal workings are explained in the github issue #455 which could be summarised by:
The way string interpolation works is actually entirely defined in Julia. What happens is that the parser (in FemtoLisp) scans the code and finds a string literal, delimited by double quotes. If it finds no unescaped $ in the string, it just creates a string literal itself — ASCIIString or UTF8String depending on the content of the string. On the other hand, if the string has an unescaped $, it punts and hands the interpretation of the string literal to the str julia macro, which generates an expression that constructs the desired strings by concatenating string literals and interpolated values. This is a nice elegant scheme that lets the parser not worry about stuff like interpolation.
I could guess that #\, #\) #\] #\} #\; which are ,, ), ], } and ; respectively are closing tokens for expressions and $ is specifying the start of next interpolation.
I have been using and still learning query expr(). I have a complex query where I cannot use if first to check if a parameter is '' - empty string.
I have to check it inside andX with nested orX using something like:
->andWhere($expr->orX($expr->eq(':sid', ''), $expr->neq('s.id', ':sid')))
Note: I know this line can be done by using if check first, I am using it just for an example, I got error says:
Error: Expected Literal, got ' OR '
I really need to compare empty string inside expr(), how?
Because '' is not an empty string. It's nothing and so it evaluates to nothing in DQL/SQL. Normally doctrine expects an named parameter. Either you create one to get quoted empty string or supply an empty string quoted by yourself.
Named parameter:
$qb->expr->eq('foo', ':foo');
$qb->expr->setParameter('foo', '');
quoted by yourself:
$qb->expr->eq('foo', "''");