create comma-separated list in xtend - xtend

I am learning xtend. What would be a nice way to create a comma separated list in xtend? (something like the SEPARATOR in xpand)
I want to produce a comma separated list of parameters in my generator:
«FOR param: row.params»
"«param.value»",
«ENDFOR»
This works but I need to omit the last comma. I tried row.params.join(",") as well but then the quotes are missing.

You may want to try
«FOR param: row.params SEPARATOR ','»
"«param.value»"
«ENDFOR»
or
row.params.join(',') [ value ]

Something like
row.params.join(', ')[''' "value" ''']
should do the trick. I put spaces before and after double quotes only to help you seeing each chars, but you may want to delete them.

Related

Postgres json_build_object adding backslash to text column

I am doing a select from a table and I want the output to be in json. For this I am using the json_build_object function.
I am getting some unexpected behavior when the select has a value with a slash inside of it.
A simple example would be:
select json_build_object('test', 'a\b');
This outputs:
{ "test": "a\\b" }
I would like to get an output of:
{ "test": "a\b" } // without extra backslash
Since your input is three characters including the first two letters and a literal backslash between them, then "a\\b" is the correct way to represent that in JSON.
If your input were made up of 2 characters, the first letter and the 'backspace' control character, that would correctly be represented in JSON as "a\b". But that is not the input you showed us. If your input is not what you want it to be, you shouldn't expect json_build_object to read your mind and fix it for you.

Regex find two characters in order, between others, ignoring punctuation

I'm trying to filter using regex in mySQL.
The field is a text field and I want to find all that match 'MD' or similar ('M.D.', 'M. D.', 'DDS, M.D.' etc.).
I do not want to accept those that contain M and D as a part of another acronym (e.g., 'DMD'). However 'DMD, M.D.' I would want to find.
Apologies if this is a simple task - I read through some regex tutorials and couldn't figure this out! Thanks.
Update:
With help from the suggestions I arrived at the following solution:
(\s|^)M\.?\s*D\.?
which works for all of my cases. The quotes in my questions were to indicate it was a string, they are not a part of the string.
You can use a regex like this:
\b(M\.?\s*D\.?|D\.?\s*D\.?\s*S\.?)
Working demo
If I have understood your requirement:
'([^'.]*[ ,]*M[. ]*D[. ]*)'
this looks for MD preceded by space comma or ' separated by 0 or more dots & spaces, followed by '
it matches all the contents between the '' marks
test: https://regex101.com/r/oV2kV8/2
In the end I found this solution works:
(\s|^)M\.?\s*D\.?(\s|$)
This allows for the 'MD' to be at the start or after another credential and to have spaces or periods or nothing between the letters.

How to remove empty comma from string using JQuery

I want to remove empty commas from the string using JQuery.
Please see the attached images to see what i mean.
This will remove all unnecessary commas in the text and update the text value:
$('.dyn-').text($('.dyn-').text().replace(/^,*|,(?=,)|,$/g, ''));
The regex is in three parts, seperated by |:
first part catches all the commas in the beginning of the string,
since they come before a word, they are all unnecessary,
second part catches all commas followed by a comma, so only the last of the
repeating commas will stay,
and third part catches a comma that is at the very end of the string, which is unnecessary.
i think it would be easier to get to the source that is causing you this trouble instead of trying it backwards..
their is a solution but why not trying to remove it from the beginning?
any chance to let us see the code?
maybe we could come up with the problem from the source.

Regex issue on SQL

Why do I get 0 when running this expression?
SELECT 'Nr. 1700-902-8423. asdasdasd' REGEXP '1+[ ,.-/\]*7+[ ,.-/\]*0+[ ,.-/\]*0+[ ,.-/\]*9+[ ,.-/\]*0+[ ,.-/\]*2+[ ,.-/\]*8+[ ,.-/\]*4+[ ,.-/\]*2+[ ,.-/\]*3+';
I need to get true, when the text contains the specified number (17009028423). There can be symbols ,.-/\ between digits.
For example, if I have number 17009028423, I need get true when in text is:
1700-902-8423
17-00,902-84.23
170/09-0.28\423
1700..902 842-3
17,.009028 4//2\3
etc.
Thanks.
There are two problems with your regular expression. First is that backslash in \] escapes the special meaning of ] to denote a character class. You need to escape your backslash: \\]. Another problem is that - denotes a range [ and ] (e.g. [a-zA-Z]). You need to escape that too or put it at the end like [a-zA-Z-] (as #tenub said). Plus the backslashes should be escaped themselves, which makes:
SELECT 'Nr. 1700-902-8423. asdasdasd' REGEXP '1[ ,./\\\\-]*7[ ,./\\\\-]*0[ ,./\\\\-]*0[ ,./\\\\-]*9[ ,./\\\\-]*0[ ,./\\\\-]*2[ ,./\\\\-]*8[ ,./\\\\-]*4[ ,./\\\\-]*2[ ,./\\\\-]*3'
You can check for yourself.
I also removed + signs in case you want to match each number only once.

Regex all uppercase with special characters

I have a regex '^[A0-Z9]+$' that works until it reaches strings with 'special' characters like a period or dash.
List:
UPPER
lower
UPPER lower
lower UPPER
TEST
test
UPPER2.2-1
UPPER2
Gives:
UPPER
TEST
UPPER2
How do I get the regex to ignore non-alphanumeric characters also so it includes UPPER2.2-1 also?
I have a link here to show it 'real-time': http://www.rubular.com/r/ev23M7G1O3
This is for MySQL REGEX
EDIT: I didn't specify I wanted all non-alphanumeric characters (including spaces), but with the help of others here it led me to this: '^[A-Z-0-9[:punct:][:space:]]+$' is there anything wrong with this?
Try
'^[A-Z0-9.-]+$'
You just need to add the special characters to the group, optionally escaping them.
Additionally if you choose not to escape the -, be aware that it should be placed at the start or the end of the grouping expression to avoid the chance that it may be interpreted as delimiting a range.
To your updated question, if you want all non-whitespace, try using a group such as:
^[^ ]+$
which will match everything except for a space.
If instead what you wanted is all non-whitespace and non-lowercase, you likely will want to use:
^[^ a-z]+$
The 'trick' used here is adding a caret symbol after the opening [ in the group expression. This indicates that we want the negation of the match.
Following the pattern, we can also apply this 'trick' to get everything but lowercase letters like this:
^[^a-z]+$
I'm not really sure which of the 3 above you want, but if nothing else, this ought to serve as a good example of what you can do with character classes.
I believe you are looking for (one?) uppercase-word match, where word is pretty much anything.
^[^a-z\s]+$
...or if you want to allow more words with spaces, then probably just
^[^a-z]+$
You just need to put in the . and -. In theory, you don't need to escape because they are inside the brackets, but I like to to remind myself to escape when I have to.
'^[A-Z0-9\.\-]+$'
Try regular expression as below:
'^[A0-Z0\\.\\-]+$'