quotes

R regular expression: isolate a string between quotes

主宰稳场 提交于 2019-12-10 15:44:59
问题 I have a string myFunction(arg1=\"hop\",arg2=TRUE) . I want to isolate what is in between quotes ( \"hop\" in this example) I have tried so far with no success: gsub(pattern="(myFunction)(\\({1}))(.*)(\\\"{1}.*\\\"{1})(.*)(\\){1})",replacement="//4",x="myFunction(arg1=\"hop\",arg2=TRUE)") Any help by a regex guru would be welcome! 回答1: You could use regmatches function also. Sub or gsub only works for a particular input , for general case you must do grabing instead of removing. > x <-

Pass shell-escaped string of arguments to a subcommand in Bourne shell

若如初见. 提交于 2019-12-10 15:37:54
问题 Say I have a command I want to run ( cmd ) and a variable containing the arguments I want to pass to the function (something like --foo 'bar baz' qux ). Like so: #!/bin/sh command=cmd args="--foo 'bar baz' qux" The arguments contain quotes, like the ones shown above, that group together an argument containing a space. I'd then like to run the command: $command $args This, of course, results in running the command with four arguments: --foo , 'bar , baz' , and qux . The alternative I'm used to

gVIM on Windows: execute buffer and paths with spaces

柔情痞子 提交于 2019-12-10 15:35:31
问题 In gVim for windows it's possible to execute current buffer via :!% command. But, unfortunately, the buffer file name is supplied to cmd.exe without quotes, so if file path has spaces gVim will not be able to execute it. Is it any easy way to fix it in order to be able execute .bat, .py etc from within gVim? 回答1: This's my guess, I don't have windows machine to try. Try :!python "%" or :!"%" credit: Eye of Hell 来源: https://stackoverflow.com/questions/1531232/gvim-on-windows-execute-buffer-and

Test whether the point is between matching quotes (emacs lisp)

萝らか妹 提交于 2019-12-10 10:13:25
问题 How do we check whether (point) is within matching "quotes" Example 1: " (point) ", but not within Example 2: "quote here" (point) "quote there", in Emacs Lisp? 回答1: What you are looking for is syntax-ppss (defined in syntax.el ). It returns 10 values, and the 4th tells you whether the point is inside a string. 回答2: (eq (nth 1 (text-properties-at (point))) font-lock-string-face) This checks whether the font of the text at point is recognized as a string (i.e. has the text property face font

Why JavaScript Compressors replace single quotes with double quotes?

旧时模样 提交于 2019-12-10 10:03:08
问题 Making some Bookmarklet, I tried to use JavaScript minifier like Google Closure Compiler or YUI Compressor. However, I didn't use these because they replace every single quotes with double quotes. I can't use a code which has double quotes, as I should enclose the code with double quotes like: <a href="javascript:alert('hello')">hello</a> So, I used MinifyJavascript for minifying. I wonder why other minifiers replace quotes. Replacing quotes doesn't minify codes. Coding style is not important

Escape all double quotes inside a single quoted string with Regex [duplicate]

不羁岁月 提交于 2019-12-10 09:46:20
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Regular Expression to escape double quotes inside single quotes I need a regex (no other language!!, best would be perl syntax REGEX or PCRE syntax REGEX) to replace all double quotes " with a \" that are inside a single quoted string. This is an example string (part of a file): var baseUrl = $("#baseurl").html(); var head = '<div id="finishingDiv" style="background-image:url({baseUrl}css/userAd/images/out_main

What are the legal delimiters for Perl 5's pick-your-own-quotes operators?

房东的猫 提交于 2019-12-10 02:06:42
问题 perlop provides various examples of the delimiters you can use for q , qq , s , etc., including ' , / , # , and { (closing with } instead of itself). But what exactly are the rules for what's allowed? I notice that you can't use, for example, whitespace or a letter (edit: a letter is allowed if you put whitespace after the operator name). 回答1: We have in Regex Quote-Like Operators in perlop under m/PATTERN/msixpodualngc With the m you can use any pair of non-whitespace (ASCII) characters as

javascript - catch SyntaxError and run alternate function

本秂侑毒 提交于 2019-12-10 01:14:01
问题 I'm trying to build something on javascript that I can have an input that can be everything like string, xml, javascript and (non-javascript string without quotes) as follows: //strings eval("'hello I am a string'"); /* note the following proper quote marks */ //xml eval(<p>Hello I am a XML doc</p>); //javascript eval("var hello = 2+2;"); So this first 3 are working well since they are simple javascript native formats but when I try use this inside javascript //plain-text without quotes eval(

RegEx: Don't match a certain character if it's inside quotes

我的梦境 提交于 2019-12-09 16:53:43
问题 Disclosure: I have read this answer many times here on SO and I know better than to use regex to parse HTML. This question is just to broaden my knowledge with regex. Say I have this string: some text <tag link="fo>o"> other text I want to match the whole tag but if I use <[^>]+> it only matches <tag link="fo> . How can I make sure that > inside of quotes can be ignored. I can trivially write a parser with a while loop to do this, but I want to know how to do it with regex. 回答1: Regular

How can I include special characters (tab, newline) in a python doctest result string?

点点圈 提交于 2019-12-09 14:14:28
问题 Given the following python script: # dedupe.py import re def dedupe_whitespace(s,spacechars='\t '): """Merge repeated whitespace characters. Example: >>> dedupe_whitespace(r"Green\t\tGround") # doctest: +REPORT_NDIFF 'Green\tGround' """ for w in spacechars: s = re.sub(r"("+w+"+)", w, s) return s The function works as intended within the python interpreter: $ python >>> import dedupe >>> dedupe.dedupe_whitespace('Purple\t\tHaze') 'Purple\tHaze' >>> print dedupe.dedupe_whitespace('Blue\t\tSky')