square-bracket

When are square brackets required in a Bash if statement?

吃可爱长大的小学妹 提交于 2019-12-17 03:04:34
问题 Usually, I use square brackets in the if statement: if [ "$name" = 'Bob' ]; then ... But, when I check if grep succeeded I don't use the square brackets: if grep -q "$text" $file ; then ... When are the square brackets necessary in the if statement? 回答1: The square brackets are a synonym for the test command. An if statement checks the exit status of a command in order to decide which branch to take. grep -q "$text" is a command, but "$name" = 'Bob' is not--it's just an expression. test is a

Square brackets meaning string wont work [duplicate]

对着背影说爱祢 提交于 2019-12-13 20:51:36
问题 This question already has answers here : What is the difference between these different ways to escape square brackets inside jQuery selectors (2 answers) Closed 5 years ago . I am a bit stuck, trying to use this jquery line to enter a result from a select option into a text area This doesnt work $("#id[txt_17]").val($(this).find("option:selected").attr("name")); This does $("#idtxt_17").val($(this).find("option:selected").attr("name")); The [ ] are coded in via an oscommerce plugin and I

C# regular expression to match square brackets

戏子无情 提交于 2019-12-13 14:52:15
问题 I'm trying to use a regular expression in C# to match a software version number that can contain: a 2 digit number a 1 or 2 digit number (not starting in 0) another 1 or 2 digit number (not starting in 0) a 1, 2, 3, 4 or 5 digit number (not starting in 0) an option letter at the end enclosed in square brackets. Some examples: 10.1.23.26812 83.33.7.5 10.1.23.26812[d] 83.33.7.5[q] Invalid examples: 10.1.23.26812[ 83.33.7.5] 10.1.23.26812[d 83.33.7.5q I have tried the following: string rex = @"

how to find a string containing a square bracket?

倖福魔咒の 提交于 2019-12-11 05:58:58
问题 i'm using a regular expression to search for a bunch of keywords in a text. All keywords are found but one: [DAM]Berlin. I know it contains a square bracket so i escaped it, but still, no luck. What am i doing wrong? here is my php code. The text to search for keywords: $textToSearch= '<p><br> Time ¦ emit LAb[au] <br> <br> [DAM]Berlin gallery<br> <br> Exhibition: February 21st - March 28th, 2009 <br> <br> Opening: Friday, February 20th, 2009 7-9 pm <br>'; The regular expression: $find='/(?![^

Square bracket notation and scope in JavaScript module pattern

痴心易碎 提交于 2019-12-10 14:53:47
问题 I have been working with the module pattern in JavaScript and have a question about scope and square bracket notation (SBN). Please consider the following simple example. (function (module) { function myMethod(text) { console.log(text); } module.init = function (name) { // here I want to do something like // eval(name)("hello"); // using SBN, e.g. ..[name].call(this, "hello"); }; })(window.Module = window.Module || {}); Module.init("myMethod"); From within the init function is it possible to

Javascript Square Bracket Notation Multiple Dynamic Properties

孤街浪徒 提交于 2019-12-07 23:32:51
问题 This may sound a bit unusual, I've never needed to use square bracket notation in this way before, and racking my brains I can't think of a way to produce the desired outcome. I'm implementing a callback wrapper to maintain the reference of this when passing methods as callbacks e.g. foo.prototype.wrap = function(name){ var wrapper, self = this; wrapper = function(){ self[name](arguments); }; return wrapper; }; // usage foo.wrap('bar'); // executes foo.bar maintaining 'this' as a reference to

What do square brackets mean in html?

隐身守侯 提交于 2019-12-06 13:29:04
I am assisting on a project right now and building out templates for the first time, trying to wrap my head around a few things but one aspect of the html that's confusing me are certain things sitting in square brackets. I've never used these in html before so I'm just wondering what they are for (when I open the page in a browser they all show up as text) Here's a bit of the code: <div class="container"> [HASBREADCRUMBS] <ol class="nav-breadcrumb"> [BREADCRUMBS] </ol> [/HASBREADCRUMBS] <h1 class="header-title" style="color:[TITLECOLOR];font-size:[TITLESIZE];">[TITLE]</h1> </div> It's using

what is the purpose of using square brackets in json? [duplicate]

痴心易碎 提交于 2019-12-04 08:03:24
问题 This question already has answers here : JavaScript arrays braces vs brackets (2 answers) Closed 3 years ago . I am new to json. Some json examples i have seen have data within the curly braces and some json examples have subdata within square brackets. { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986",

Regex for getting information from square brackets

人走茶凉 提交于 2019-12-01 23:00:21
I'm attempting to make something like shortcodes in WordPress, and I'm looking for a regex that will take something like [title:This is a title] and turn it to just This is a title . It would also be useful if someone could suggest a way to take something like [code:some code] and turn that into an array in the form of array( [0] => 'code' [1] => 'some code') or array( 'code' => 'some code' I've tried a few different regexes I've found here and there, but none of them seem to work. Thanks preg_replace('/\[.*?:(.*?)\]/', '$1', $str); CodePad . If you wanted to capture the text before the colon,

What is the difference between curly brace and square bracket in Python?

匆匆过客 提交于 2019-11-29 19:51:32
what is the difference between curly brace and square bracket in python? A ={1,2} B =[1,2] when I print A and B on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use {} and [] to initialize different variables. E.g. A=[] , B={} Is there any difference there? Curly braces create dictionaries or sets . Square brackets create lists . They are called literals ; a set literal: aset = {'foo', 'bar'} or a dictionary literal: adict = {'foo': 42, 'bar': 81} empty_dict = {} or a list literal: alist = ['foo', 'bar', 'bar'] empty_list = [] To create an empty set, you