Yaml File escape characters in multiline string - pyyaml

I want to use \n character in multiline string but YAML doesn't allow me to use \n character. How can I use \n character.
My YAML:
treeroot:
branch1:
name: >
hello my friend\n how are you ?
i am fine and you ?\n
yes\nthanks
branch1-1:
name: Node 1-1
branch2:
name: Node 2
branch2-1:
name: Node 2-1
I know, we can use \n character in single line mode but I want use it in multiline.

There is no such thing as 'single-line' mode in YAML. You have scalars that represent strings and they can be plain (no quotes), single and double quoted. Apart from that, in block-style, you have literal and folded style.
Literal and folded style are always multiline (assuming you count the line with the | resp. the >), but the other scalars can be multiline as well. In the later case double new-lines in the string are transformed into newlines and other new-lines into spaces. Since escaping with backslash is only allowed in double quoted strings the following YAML is what you need to use:
treeroot:
branch1:
name: "hello my friend\n how are you ?
i am fine and you ?\n
yes\nthanks"
branch1-1:
name: Node 1-1
branch2:
name: Node 2
branch2-1:
name: Node 2-1
The value for the first key 'name' is the same as if specified as
"hello my friend\n how are you ? i am fine and you ?\n yes\nthanks"

Related

how can i remove special emoji's using xquery from text

I have a $text = "Hello ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„ ๐Ÿ’œ ๐Ÿ™๐Ÿป ๐Ÿฆฆรผรครถ$"
I wanted to remove just emoji's from the text using xquery. How can i do that?
Expected result : "Hello รผรครถ$"
i tried to use:
replace($text, '\p{IsEmoticons}+', '')
but didn't work.
it just removed smiley's
Result now: "Hello ๐Ÿ’œ ๐Ÿ™๐Ÿป ๐Ÿฆฆรผรครถ$"
Expected result : "Hello รผรครถ$"
Thanks in advance :)
I outlined the approach in my answer to the original question, which I updated based on your comment asking about how to strip out ๐Ÿ’œ.
Quoting from that expanded answer:
The "Emoticons" block doesn't contain all characters commonly associated with "emoji." For example, ๐Ÿ’œ (Purple Heart, U+1F49C), according to a site like https://www.compart.com/en/unicode/U+1F49C that lets you look up Unicode character information, is from:
Miscellaneous Symbols and Pictographs, U+1F300 - U+1F5FF
This block is not available in XPath or XQuery processors, since it is neither listed in the XML Schema 1.0 spec linked above, nor is it in Unicode block names for use in XSD regular expressionsโ€”a list of blocks that XPath and XQuery processors conforming to XML Schema 1.1 are required to support.
For characters from blocks not available in XPath or XQuery, you can manually construct character classes. For example, given the purple heart character above, we can match it as follows:
replace("Purple ๐Ÿ’œ heart", "[๐ŸŒ€-๐Ÿ—ฟ]", "")
This returns the expected result:
Purple Heart
This approach can be applied to ๐Ÿ™๐Ÿป , ๐Ÿฆฆ, or any other character:
Locate the character's unicode block.
Craft your regular expression with the block name (if available in XPath) or character class.
Alternatively, rather than locating the blocks of characters you want to strip out, you could identify the blocks of characters you want to preserve. For example, given the example string in the original post, perhaps the goal is to preserve only those characters in the "Basic Latin" block. To do so, we can match characters NOT in this block via the \P Category Escape:
xquery version "3.1";
let $text := "Hello ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„ ๐Ÿ’œ ๐Ÿ™๐Ÿป ๐Ÿฆฆรผรครถ$"
return
replace($text, "\P{IsBasicLatin}", "")
This query returns:
Hello $
Notice that this has stripped out the characters with diacritics, which perhaps isn't desired. These characters with diacritics belong to the Latin-1 Supplement block. To preserve characters from both the Latin and Latin-1 Supplement blocks, we'd need to adjust the query as follows:
xquery version "3.1";
let $text := "Hello ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„ ๐Ÿ’œ ๐Ÿ™๐Ÿป ๐Ÿฆฆรผรครถ$"
return
replace($text, "[^\p{IsBasicLatin}\p{IsLatin-1Supplement}]", "")
... which returns:
Hello รผรครถ$
This now preserves the characters with diacritics.
To be precise about the characters you preserve or remove, you need to consult the Unicode blocks and charts.

How to delete only (anyword).com in Regex?

I'd like to match the following
My best email gmail.com
email com
email.com
to become
My best email
email com
*nothing*
Specifically, I'm using Regex for R, so I know there are different rules for escaping certain characters. I'm very new to Regex, but so far I have
\ .*(com)
which makes the same input
My
But this code does not work for instances where there are no spaces like the third example, and removes everything past the first space of a line if the line has a ".com"
Use the following solution:
x <- c("My best email gmail.com","email com", "email.com", "smail.com text here")
trimws(gsub("\\S+\\.com\\b", "", x))
## => [1] "My best email" "email com" "" "text here"
See the R demo.
The \\S+\\.com\\b pattern matches 1+ non-whitespace chars followed by a literal .com followed by the word boundary.
The trimws function will trim all the resulting strings (as, e.g. with "smail.com text here", when a space will remain after smail.com removal).
Note that TRE regex engine does not support shorthand character classes inside bracket expressions.

Symfony2, missing controller's first letter from a config routes

I'm getting a weird error in console after the command 'route:debug'.
`
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Cannot import resource "....../src/Acme/MyBundle/Resources/config/routes.yml"
from "....../app/config/routing.yml".
(Class could not be determined for Controller identified by
"Acme\MyBundle\Controllerโ€ฉ\ ageController"
`
where in Acme/MyBundle/config/routes.yml I have
resource: "Acme\MyBundle\Controller\PageController"
linked from app/config/routing.yml
resource: "#AcmeMyBundle/Resources/config/routes.yml"
By examining the code it seems that for some reason Yaml::parse($path) returns in $config['resource'] the controller name as "ageController", without the "P" letter
...Where am I so wrong?
Many thanks
--------EDIT-------
Thanks for the useful response from #piotrekkr.
By escaping "P" char, it works. thanks Piottekr
So it became:
Acme\MyBundle\Controller\\PageController
I think the reason is that \P is special character in YAML. From http://yaml.org/spec/1.2/spec.html#id2776092
5.7. Escaped Characters
All non-printable characters must be escaped. YAML escape sequences
use the โ€œ\โ€ notation common to most modern computer languages. Each
escape sequence must be parsed into the appropriate Unicode character.
The original escape sequence is a presentation detail and must not be
used to convey content information.
Note that escape sequences are only interpreted in double-quoted
scalars. In all other scalar styles, the โ€œ\โ€ character has no special
meaning and non-printable characters are not available.
And the character
[58] ns-esc-paragraph-separator ::= โ€œPโ€ - Escaped Unicode paragraph separator (#x2029) character.
Try using \\P in your YAML

Text box validation using regular expression in asp.net

I have a textbox and have to use the regular expressions in asp.net
My text should not allow the spaces in first and last place.
Output should be:
Valid:
[India Bangalore]
Not valid:
[ India Bangalore ]
i.e : user can enter the spaces in between the words but not in first position and last position.
If you have solution in JavaScript that is also fine.
Trim() should remove any trailing or leading spaces.
Try this please :
^[^\s].*[^\s]$
It simply match input which:
not to start with any white space ^[^\s] followed by any character even white spaces .* and not end with any white space [^\s]$.
Any way calling Trim() method on input string in server-side is much easy .

Regular Expression Validator -Not taking lower case alphabets

I have a problem with Regular Expression Validator. It takes 0-9, A-Z and prevents ' and " But it not takes lowercase alphabets. Here is my expression ^[a-z|A-Z|0-9|]+[^\"\']*$
You should use:
^[a-zA-Z0-9]+$
The | , "OR", should be used in groups ([a-z]|[A-Z|..). Also, by adding [^"']*, you allow users to enter phrases like a ##%$^&&&&*&^&*#$##$ (starting with alphanumeric character, followed by any non-quote char).
My suggested RegEx means:
^ <start>
[a-zA-Z0-9] Any alplhanumeric character, case-insensitive
+ at least once
$ <end>
If all you need is that the text contain exclusively letters and digits, you could use:
/^[a-zA-Z0-9]+$/
Notice that there is no | in the character set, all the things you put inside the [] are implicitly "or"ed together. Adding a | would allow for a literal | in the text.
Change the + to * if an empty string is valid. You don't need to exclude quotes specifically, since you're not allowing them in at all.
Shorter version of similar regexp:
^[\w]+$
Note: it will also match non-Latin characters and "_", which may be either good or bad depending on your requirements.

Resources