Symfony, twig, date - date

Easy question but i could find answer here: http://twig.sensiolabs.org/doc/filters/date.html
I have this:
user.birthday|date("Y\m\d")
but the output is to example: 19930224
and i want to separate it buy "/" to example like: 1993/02/24
Any idea? Thx!

You cannot use backslash \ because it is used for escaping characters. You can use / instead.

In the date() function, you need to escape \ with a second one as \\.
And as said in the twig documentation:
To escape words and characters in the date format use \\ in front of
each character
So you need to escape it as following in your twig template:
{{ user.birthday|date('Y\\\\m\\\\d') }}

Related

How to replace dot in Helm template string

I'm trying to replace all the dot characters in a helm template string with \., like so:
{{- regexReplaceAllLiteral "\." "https://endpoint.index.up" "\\\." -}}
I want this to output - https://endpoint\.index\.up
This is giving me a parse error. I've tried a bunch of different combinations but nothing is replacing the dot characters. Any help appreciated!
If you're just trying to replace a fixed string, replace will be easier to use. (This is one of the Sprig string functions so it will work with other tools that also embed the Sprig template extensions.)
{{- "https://endpoint.index.up" | replace "." "\\." -}}
It doesn't look like backslash is treated specially in the replacement string argument to regexReplaceAllLiteral so it should work so long as the replacement string argument is backslash dot; inside the double-quoted string syntax you need to double the backslash but you do not need to escape the period, so again "\\." and not "\\\.".

Datastage-What is the escape character for # in execute command activity?

What is the escape character for # in execute command activity? Well i was trying to replace one string in file with "#",but datastage treating # as job parameter and expecting the value to be assigned in datastage parameters.For that we need escape character for "#". I tried using \ and / as escape characters but none of them solved my problem. Thank You.
Just wanted to add that the actual answer to this question is:
\043
The expression mentioned previously (!/^\043/) is related to the first link #Damienknight posted.
Use awk to replace the # sign, and you can use the octal character code for # in the regular expression:
!/^\043/
There is a thread in DSXchange that discusses this.
Here is a guide on escape sequences in AWK expressions.
A table with ascii codes, including a column for octal values.

How to quote $1 in yasnippet

Suppose, I have the following yasnippet:
my $dir = __FILE__;
$dir =~ s/(.*)\/.*/$1/;
$1 here is the regular expression first match. Not yasnippet special symbol. How can I quote it, so it is inserted into the code as is?
From the documentation:
Arbitrary text can be included as the content of a template. They are usually interpreted as plain text, except $ and `. You need to use \ to escape them: \$ and \`. The \ itself may also needed to be escaped as \\ sometimes.
So use \$ to get a literal '$' in your snippet.

PostgreSQL regexp_replace with matched expression

I am using PostgreSQL regexp_replace function to escape square brackets, parentheses and backslash in a string so that I could use that string as a regex pattern itself (there are other manipulations done on this string as well before using it, but they are outside the scope of this question. The idea is to replace:
[ with \[
] with \]
( with \(
) with \)
\ with \\
Postgres documentation page on regular expressions states the following:
The replacement string can contain \n, where n is 1 through 9, to
indicate that the source substring matching the n'th parenthesized
subexpression of the pattern should be inserted, and it can contain \&
to indicate that the substring matching the entire pattern should be
inserted. Write \ if you need to put a literal backslash in the
replacement text.
However regexp_replace('abc [def]', '([\[\]\(\)\\])', E'\\\1', 'g'); produces abc \ def\.
Further down on that same page, an example is given, which uses \\1 notation - so I tried that.
Yet, regexp_replace('abc [def]', '([\[\]\(\)\\])', E'\\\\1', 'g'); produces abc \1def\1.
I would guess this is expected, but regexp_replace('abc [def]', '([\[\]\(\)\\])', E'.\\1', 'g'); produces abc .[def.]. That is, escaping works with characters other than the standard backslash.
At this point I don't know how to proceed. What can I do to actually give me the replacement I want?
OK, found the answer. Apparently, I need to double-escape the backslash in the replacement. Also, I need to E-prefix and double-escape backslashes in the search pattern on older versions of postgres (8.3 in my case). The final code looks like this:
regexp_replace('abc [def]', E'([\\[\\]\\(\\)\\\\\?\\|_%])', E'\\\\\\1', 'g')
Yes, it looks horrible, but it works :)
it's simpliest way
select regexp_replace('abc [def]', '([\[\]\(\)\\])', '\\\1', 'g')

How do I replace "\" with "//" in Perl?

I want to substitute, the "\" that appears in the Windows directory link to a "/".
I tried using s//\////g, but it doesn't seem to do the trick.
s[\\][//]g
\ needs to be escaped in a regex
/ does not
Avoid using / to delimit regex sections when using / in the expression itself (it makes things much more readable!)
... but you should probably use something like Path::Class.
First of all, using a different separator than \ will make your regex more readable.
Then you have to replace the \ with \\, or it will be used to escape the following character (a / in the regex you are using).
$link =~ s|\\|//|g;
I think this should do it:`
$str =~ s{\\}{//}g;