get text with whitespaces when generate grammar - xtext

Is it possible to get a text with whitespaces?
Example rule:
rule: 'text' text+=ID+
I can obtain the text as a list and could add a whitespace programmatically for each list element, but i don't want that approach. I actually don't need a list. I want one single variable holding the text with whitespaces.
STRING works fine, but it has those ugly quotes, i don't want those quotes as well.
Maybe someone has an idea how to achieve that?

You can use a Datatype-Rule like this:
rule: 'text' text+= MyText ;
MyText:
ID+
;
Lookup some details in the Reference Documentation in the section Data Type Rules.

Related

Teradata:Get a specific part of a large variable text field

My first Post: (be kind )
PROBLEM: I need to extract the View Name from a Text field that contains a full SQL Statements so I can link the field a different data source. There are two text strings that always exist on both sides of the target view. I was hoping to use these as identifying "anchors" along with a substring to bring in the View Name text from between them.
EXAMPLE:
from v_mktg_dm.**VIEWNAME** as lead_sql
(UPPER CASE/BOLD is what I want to extract)
I tried using
SELECT
SUBSTR(SQL_FIELD,INSTR(SQL_FIELD,'FROM V_MKTG_TRM_DM.',19),20) AS PARSED_FIELD
FROM DATABASE.SQL_STORAGE_DATA
But am not getting good results -
Any help is appreciated
You can apply a Regular Expression:
RegExp_Substr_gpl(SQL_FIELD, '(v_mktg_dm\.)(.*?)( AS lead_sql)',1,1,'i',2)
This looks for the string between 'v_mktg_dm.' and ' AS lead_sql'.
RegExp_Substr_gpl is an undocumented variation of RegExp_Substr which simplifies the syntax for ignoring parts of the match

Replace a exact string using Regex in ruby

Consider the the following text
The capital asset as defined in section 2(14) is an exhaustive definition which encompasses all properties of any kind with certain exceptions but the key word is that the property should be "held" section 2.
Now I want to find section 2, for the same I have written the following Regex:
/\bsection+\.*\s+2\b/i
But it is also matching section 2 of section 2(14). I just want it to only match the exact text, not the part of text which is matching with the regex. I know I need to modify the regex, but what are the changes required?
Try with \bsection+\.*\s+2([ .,;?|!])/i . This will only match with section 2 if it is followed by a space or a punctuation mark different than (.
/\bsection+.*\s+2\b([[:punct:]]|\s/
basically you would want the word to end with whitespace or a punctuation.

Regular expression string between tags "<string>"

I have a string "<wpf><xaml><wpf-controls>".
I need the string between the tags in array format.
How do I get this?
The regex for this problem is really simple it is: /<(.*?)>/
For the array part is would reference to the answer on how to use one line regular expression to get matched content
EDIT:
for array of the insides of the tags use <wpf><xaml><wpf-controls>".scan(/(?:<(.*?)>)*/)
The (?: .. ) groups the tag together and the * says we want 0 or more of that group :)
'<wpf><xaml><wpf-controls>'.scan(/<(.*?)>/).map(&:first)

How can I update parts of the string that matches some regexp

I have string "(1,2,3,4,5,6),(1,2,3)" I would like to change it to "('1','2','3','4','5','6'),('1','2','3')" - replase all parts that mathces /([^,)("])/ with the '$1', '$2' etc
"(1,2,3,4,5,6),(1,2,3)".gsub(/([^,)("]\w*)/,"'\\1'")
gsub is a "global replace" method in String class. It finds all occurrences of given regular expression and replaces them with the string given as the second parameter (as opposed to sub which replaces first occurrence only). That string can contain references to groups marked with () in the regexp. First group is \1, second is \2, and so on.
Try
mystring.gsub(/([\w.]+)/, '\'\1\'')
This will replace numbers (ints/floats) and words with their "quote-surrounded" selves while leaving punctuation (except the dot) alone.
UPDATED: I think you want to search for this
(([^,)("])+)
And replace it with this
'$1'
the looks for anything 1 or more times and assigns it to the $1 variable slot due to using the parenthesis around the "\d". The replace part will use what it finds as the replacement value.

Rails validates_format_of

I want to use validates_format_of to validate a comma separated string with only letters (small and caps), and numbers.
So.
example1, example2, 22example44, ex24
not:
^&*, <> , asfasfsdafas<#%$#
Basically I want to have users enter comma separated words(incl numbers) without special characters.
I'll use it to validate tags from acts_as_taggable_on. (i don't want to be a valid tag for example.
Thanks in advance.
You can always test out regular expressions at rubular, you would find that both tiftiks and Tims regular expressions work albeit with some strange edge cases with whitespace.
Tim's solution can be extended to include leading and trailing whitespace and that should then do what you want as follows :-
^\s*[A-Za-z0-9]+(\s*,\s*[A-Za-z0-9]+)*\s*$
Presumably when you have validated the input string you will want to turn it into an array of tags to iterate over. You can do this as follows :-
array_var = string_var.delete(' ').split(',')
^([a-zA-Z0-9]+,\s*)*[a-zA-Z0-9]+$
Note that this regex doesn't match values with whitespace, so it won't match multiple words like "abc xyz, fgh qwe". It matches any amount of whitespace after commas. You might not need ^ or $ if validates_format_of tries to match the whole string, I've never used Rails so I don't know about that.
^[A-Za-z0-9]+([ \t]*,[ \t]*[A-Za-z0-9]+)*$
should match a CSV line that only contains those characters, whether it's just one value or many.

Resources