I want to change this below using Regular Expression
<script type="text/javascript" language="javascript" src="/Common/Scripts/UserControls/Form.js"></script>
<script type="text/javascript" language="javascript" src="<%=VirtualPathUtility.ToAbsolute("~/Common/Scripts/UserControls/Form.js")%>></script>
You can try the following:
Find:
\<script type\=\"text\/javascript\" language\=\"javascript\" src="{[^"]+}"\>\<\/script\>
Replace:
<script type="text/javascript" language="javascript" src="<%=VirtualPathUtility.ToAbsolute("~\1")%>></script>
The key things to note:
You can match an expression for use in the replace section with braces {}. I use [^"]+ to capture all characters between the quotes - the [] matches a set of characters, where ^ means "not" - so [^"] matches anything except a quote. Then + means match one or more (non-quote characters).
Some characters have special meaning, so you can escape them with \. You can safely escape most chracters that don't have meaning if you put an extra \ unnecessarily in front of them, so I am overzealous just to be safe.
Use \1, \2, \3, etc. to use captured groups in the replace expression. So I'm using \1 to refer to the src attribute value matched in the find.
Related
I recently used the <<- operator to output a multi-line string, like this:
<<-form
<h1>Name to say hi!</h1>
<form method="post">
<input type="text" name="name">
<input type="submit" value="send">
</form>
form
But I stole the <<- operator from some Open Source code, but I didn't find any documentation on it.
I kinda figured out that it works the same as in bash:
$ cat <<EOF >> form.html
> <h1>Name to say hi!</h1>
> <form method="post">
> <input type="text" name="name">
> <input type="submit" value="send">
> </form>
> EOF
Does it work that way? I just wanna find documentation on it.
From The Ruby Programming Language:
Here Documents
For long string literals, there may be no single character delimiter that can be used without worrying about remembering to escape characters within the literal. Ruby's solution to this problem is to allow you to specify an arbitrary sequence of characters to serve as the delimiter for the string. This kind of literal is borrowed from Unix shell syntax and is historically known as a here document. (Because the document is right here in the source code rather than in an external file.)
Here documents begin with << or <<-. These are followed immediately (no space is allowed, to prevent ambiguity with the left-shift operator) by an identifier or string that specifies the ending delimiter. The text of the string literal begins on the next line and continues until the text of the delimiter appears on a line by itself. For example:
document = <<HERE # This is how we begin a here document
This is a string literal.
It has two lines and abruptly ends...
HERE
The Ruby interpreter gets the contents of a string literal by reading a line at a time from its input. This does not mean, however, that the << must be the last thing on its own line. In fact, after reading the content of a here document, the Ruby interpreter goes back to the line it was on and continues parsing it. The following Ruby code, for example, creates a string by concatenating two here documents and a regular single-quoted string:
greeting = <<HERE + <<THERE + "World"
Hello
HERE
There
THERE
The <<HERE on line 1 causes the interpreter to read lines 2 and 3. And the <<THERE causes the interpreter to read lines 4 and 5. After these lines have been read, the three string literals are concatenated into one.
The ending delimiter of a here document really must appear on a line by itself: no comment may follow the delimiter. If the here document begins with <<, then the delimiter must start at the beginning of the line. If the literal begins with <<- instead, then the delimiter may have whitespace in front of it. The newline at the beginning of a here document is not part of the literal, but the newline at the end of the document is. Therefore, every here document ends with a line terminator, except for an empty here document, which is the same as "":
empty = <<END
END
If you use an unquoted identifier as the terminator, as in the previous examples, then the here document behaves like a double-quoted string for the purposes of interpreting backslash escapes and the # character. If you want to be very, very literal, allowing no escape characters whatsoever, place the delimiter in single quotes. Doing this also allows you to use spaces in your delimiter:
document = <<'THIS IS THE END, MY ONLY FRIEND, THE END'
.
. lots and lots of text goes here
. with no escaping at all.
.
THIS IS THE END, MY ONLY FRIEND, THE END
The single quotes around the delimiter hint that this string literal is like a single-quoted string. In fact, this kind of here document is even stricter. Because the single quote is not a delimiter, there is never a need to escape a single quote with a backslash. And because the backslash is never needed as an escape character, there is never a need to escape the backslash itself. In this kind of here document, therefore, backslashes are simply part of the string literal.
You may also use a double-quoted string literal as the delimiter for a here document. This is the same as using a single identifier, except that it allows spaces within the delimiter:
document = <<-"# # #" # This is the only place we can put a comment
<html><head><title>#{title}</title></head>
<body>
<h1>#{title}</h1>
#{body}
</body>
</html>
# # #
Note that there is no way to include a comment within a here document except on the first line after the << token and before the start of the literal. Of all the # characters in this code, one introduces a comment, three interpolate expressions into the literal, and the rest are the delimiter
http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#here_doc
This is the Ruby "here document" or heredoc syntax. The addition of the - indicates the indent.
The reason why you cannot find any documentation on the <<- operator is because it isn't an operator. It's literal syntax, like ' or ".
Specifically, it's the here document syntax which is one of the many syntactic forms of string literals in Ruby. Ruby here documents are similar to POSIX sh here documents, but handling of whitespace removal is different: in POSIX sh here documents delimited by <<-, only leading tabs are removed, but they are removed from the contents of the string, whereas in Ruby all leading whitespace is removed, but only from the delimiter.
This post will tell you everything you need to know about the "heredoc" string syntax. In addition, you can view the rubydoc page for string syntax.
I have a regex in Ruby to match a huge list of emoticons
/\|?>?[:*;Xx8=<(%)D]-?'?,?o?\_^?[-DOo0S*Ppb3c:;\/\\|)(}{\]><]\)?/
But it doesnt match a few emoticons like
:'-(
and
:*(
The link with my set of matching emoticons is http://rubular.com/r/1vnWEvN76v
How do I match the unmatched ones ?
use r":'-\(" for first example and r":\*\(" for second . and you can add them with pipe (|) to your regex ! but its depend on what you want to be matched with your regex , also you can add them after other regexes or use & or ..
Note that ( and * are regex symbols and you need \ before them !
in this case for your regex you just need to add |\( end of your regex:
\|?>?[:*;Xx8=<(%)D]-?'?,?o?\_^?[-DOo0S*Ppb3c:;\/\\|)(}{\]><]\)?|\(
I read similar titles but I couldn't make it run..
Now, I have a code like this (originally ereg):
if (preg_match("[^0-9]",$qrcode_data_string)){
if (preg_match("[^0-9A-Z \$\*\%\+\-\.\/\:]",$qrcode_data_string)) {
I also tried using / at the beginning and end of rule but didn't work.
Any replies welcome.
With the preg_* functions you need delimiters around the pattern:
if (preg_match("#[^0-9]#", $qrcode_data_string)) {
# ^ ^
From the documentation:
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).
How do i search a particular line based on string match and replace it with another sting.
Below is the example of a html strong which i need to modify using bash script.
< link type="text/css" rel="stylesheet" href="https://teststore.xxx.com/store/downpanel.css">
change to:
< link type="text/css" rel="stylesheet" href="https://testsstore.xxx.com/store/downpanel.css">
i.e teststore with testsstore. just trying to add 's' .
I guess i need to match all the string. because downpanel.css is the one which differentiate which line to be edit with 's'.
I being said that this can be achieved by Regualar expression.. but i couldn't able to make it . any help with syntax would be highly greatful.
thanks.
jack
If you need to replace all occurrences of this link, just do
sed 's_"https://teststore.xxx.com/store/downpanel.css"_"https://testsstore.xxx.com/store/downpanel.css"_g' old_file > new_file
If you really need to match the whole part you show, then put in in the sed command. Beware of line breaks, they will spoil the match if encountered somewhere in the middle.
Here's a reference for sed. Or just type man sed on Linux.
To solve problems like this you generally use a sed construct like this:
sed -e '/unique pattern/s/string or pattern/replacement string/' file
The initial /unique pattern/ part constrains the substitution to lines which the pattern given. For simple cases, like yours, it may be sufficient to simply perform the substitution on all lines containing teststore, thus the unique pattern part can be omitted and the substitute becomes global:
sed -e 's/teststore/testsstore/' file
If this is a problem for you and replaces something it should not you can use the original form, perhaps like this:
sed -e '/link.*teststore/s/teststore/testsstore/' file
To help limit the impact.
Note that this will only write the modified version of file to stdout. To make the change in place, add the -i switch to sed.
I find myself doing a ton of jQuery these days, so I started to abstract out some of the common things I do into snippets. I look forward to sharing these with the community, but I'm running into an issue right now.
The literals in snippets are defined by adding dollar signs ($) around the name of the literal to delimit where the value you would like to provide will go. This is difficult because jQuery uses the dollar sign notation in order to use a lot of its functionality.
What is the escape sequence for snippets, so I am able to use the dollar sign, and have my snippets still function?
To have a literal $ try doubling it: $$
This is the right way for Visual Studio Code: \\$.
This makes the $ a literal part of the snippet rather than the start of a $-prefixed construct.
There is an "Delimiter" attribute defined for a Code element. This defaults to $ but you can set it to a different character like ~ or so.
...
<Snippet>
<Code Language="JavaScript" Delimiter="~"><![CDATA[(function ($) {
$(document).ready(function () {
});
})(jQuery);]]></Code>
</Snippet>
...
Although the jQuery response is valid, it's a nicer syntax to use the $ notation.
I've found an answer: Making the $ character a literal with a default value of $.
<Literal Editable="true">
<ID>dollar</ID> <ToolTip>replace the dollar sign character</ToolTip> <Default>$</Default> <Function> </Function> </Literal>
I used this for a formattable string in C#. I used the example above from cory-fowler verbatim:
<Literal Editable="true">
<ID>dollar</ID>
<ToolTip>Replace the dollar sign character</ToolTip>
<Default>$</Default>
<Function></Function>
</Literal>
Usage (line breaks are added for clarity on Stack Overflow, not in the original.):
string errMessage = $dollar$"Error occurred in
{MethodBase.GetCurrentMethod().Module}, in procedure
{MethodBase.GetCurrentMethod().Name}: {ex.Message}".ToString();
Thanks, cory-fowler!
I found the above cory-fowler answer useful, but was frustrated that the literal $ was pre-selected when executing a C# snippet in VS 2019...
It was also ignoring my $end$ keyword...
<![CDATA[string Literal_edit_true = $dollar$"$end$";]]>
Simply changing to Editable=false resolved the issue and now the cursor appears at $end$ ready to type...
<Snippet>
<Code Language="CSharp">
<![CDATA[string Literal_edit_false = $dollar$"$end$";]]>
</Code>
<Declarations>
<Literal Editable="false">
<ID>dollar</ID>
<ToolTip>Replace the dollar sign character</ToolTip>
<Default>$</Default>
<Function></Function>
</Literal>
</Declarations>
</Snippet>