Search Results

Search found 192 results on 8 pages for 'parentheses'.

Page 5/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • Regex for capturing numbered text list

    - by crunchyt
    I have a test list that I am trying to capture data from using a regex. Here is a sample of the text format: (1) this is a sample string /(2) something strange /(3) another bit of text /(4) the last one/ something!/ I have a Regex that currently captures this correctly, but I am having some difficulty with making it work under outlier conditions. Here is my regex /\(?\d\d?\)([^\)]+)(\/|\z)/ Unfortunately some of the data contains parentheses like this: (1) this is a sample string (1998-1999) /(2) something strange (blah) /(3) another bit of text /(4) the last one/ something!/ The substrings '(1998-1999)' and '(blah)' make it fail! Anyone care to have a crack at this one? Thank you :D

    Read the article

  • generalizing the pumping lemma for UNIX-style regular expressions

    - by Avi
    Most UNIX regular expressions have, besides the usual *,+,? operators a backslash operator where \1,\2,... match whatever's in the last parentheses, so for example L=(a)b\1* matches the (non regular) language a^n b a^n On one hand, this seems to be pretty powerful since you can create (a*)b\1b\1 to match the language a^n b a^n b a^n which can't even be recognized by a stack automaton. On the other hand, I'm pretty sure a^n b^n cannot be expressed this way. Two questions: 1. Is there any literature on this family of languages (UNIX-y regular). In particular, is there a version of the pumping lemma for these? 2. Can someone prove (or perhaps disprove) that a^n b^n cannot be expressed this way? Thanks

    Read the article

  • Javascript comma operator

    - by Claudiu
    When combining assignment with comma (something that you shouldn't do, probably), how does javascript determine which value is assigned? Consider these two snippets: function nl(x) { document.write(x + "<br>"); } var i = 0; nl(i+=1, i+=1, i+=1, i+=1); nl(i); And: function nl(x) { document.write(x + "<br>"); } var i = 0; nl((i+=1, i+=1, i+=1, i+=1)); nl(i); The first outputs 1 4 while the second outputs 4 4 What are the parentheses doing here?

    Read the article

  • Helper Casting Functions -- Is it a code smell?

    - by Earlz
    I recently began to start using functions to make casting easier on my fingers for one instance I had something like this ((Dictionary<string,string>)value).Add(foo); and converted it to a tiny little helper function so I can do this ToDictionary(value).Add(foo); Is this a code smell? Also, what about simpler examples? For example in my scripting engine I've considered making things like this ((StringVariable)arg).Value="foo"; be ToStringVar(arg).Value="foo"; I really just dislike how inorder to cast a value and instantly get a property from it you must enclose it in double parentheses. I have a feeling the last one is much worse than the first one though (also I've marked this language agnostic even though my example is C#)

    Read the article

  • Splitting a string according to a delimiter when elements in the string can contain the delimiter

    - by Vivin Paliath
    I have a string that looks like this: "#Text() #SomeMoreText() #TextThatContainsDelimiter(#blah) #SomethingElse()" I'd like to get back [#Text(), #SomeMoreText(), #TextThatContainsDelimiter(#blah), #SomethingElse()] One way I thought about doing this was to require that the # to be escaped into \#, which makes the input string: "#Text() #SomeMoreText() #TextThatContainsDelimiter(\#blah) #SomethingElse()" I can then split it using /[^\\]#/ which gives me: [#Text(), SomeMoreText, TextThatContainsDelimiter(\#blah), SomethingElse()] The first element will contain # but I can strip it out. However, is there a cleaner way to do this without having to escape the #, and which ensures that the first element will not contain a #? Basically I'd like it to split by # only if the # is not enclosed by parentheses. My hunch is that since the # is context-sensitive and and regular expressions are only suited for context-free strings, this may not be the right tool. If so, would I have to write a grammar for this and roll my own parser/lexer?

    Read the article

  • How do I parse boolean logic?

    - by d03boy
    I need to write a boolean logic parser which will translate the boolean logic language to a SQL WHERE clause. The order of the operands will always be in the correct order (with value on the right). Here is a relatively simple example. There could be nested parentheses and the use of NOT operators, etc. (CACOUNT=01 OR CACOUNT=02 OR CACOUNT=03 OR CACOUNT=05 OR CACOUNT=07 OR CACOUNT=09 OR CACOUNT=12 OR CACOUNT=13 OR CACOUNT=18) AND Q4=1 AND NAME=TIMOTHY Here is what the WHERE clause would resemble. WHERE ( EXISTS ( SELECT 1 FROM MyVerticalTable b WHERE b.Key=a.Key AND b.Key='CACOUNT' AND b.Value='01' ) )

    Read the article

  • Threading extra state through a parser in Scala

    - by Travis Brown
    I'll give you the tl;dr up front I'm trying to use the state monad transformer in Scalaz 7 to thread extra state through a parser, and I'm having trouble doing anything useful without writing a lot of t m a -> t m b versions of m a -> m b methods. An example parsing problem Suppose I have a string containing nested parentheses with digits inside them: val input = "((617)((0)(32)))" I also have a stream of fresh variable names (characters, in this case): val names = Stream('a' to 'z': _*) I want to pull a name off the top of the stream and assign it to each parenthetical expression as I parse it, and then map that name to a string representing the contents of the parentheses, with the nested parenthetical expressions (if any) replaced by their names. To make this more concrete, here's what I'd want the output to look like for the example input above: val target = Map( 'a' -> "617", 'b' -> "0", 'c' -> "32", 'd' -> "bc", 'e' -> "ad" ) There may be either a string of digits or arbitrarily many sub-expressions at a given level, but these two kinds of content won't be mixed in a single parenthetical expression. To keep things simple, we'll assume that the stream of names will never contain either duplicates or digits, and that it will always contain enough names for our input. Using parser combinators with a bit of mutable state The example above is a slightly simplified version of the parsing problem in this Stack Overflow question. I answered that question with a solution that looked roughly like this: import scala.util.parsing.combinator._ class ParenParser(names: Iterator[Char]) extends RegexParsers { def paren: Parser[List[(Char, String)]] = "(" ~> contents <~ ")" ^^ { case (s, m) => (names.next -> s) :: m } def contents: Parser[(String, List[(Char, String)])] = "\\d+".r ^^ (_ -> Nil) | rep1(paren) ^^ ( ps => ps.map(_.head._1).mkString -> ps.flatten ) def parse(s: String) = parseAll(paren, s).map(_.toMap) } It's not too bad, but I'd prefer to avoid the mutable state. What I want Haskell's Parsec library makes adding user state to a parser trivially easy: import Control.Applicative ((*>), (<$>), (<*)) import Data.Map (fromList) import Text.Parsec paren = do (s, m) <- char '(' *> contents <* char ')' h : t <- getState putState t return $ (h, s) : m where contents = flip (,) [] <$> many1 digit <|> (\ps -> (map (fst . head) ps, concat ps)) <$> many1 paren main = print $ runParser (fromList <$> paren) ['a'..'z'] "example" "((617)((0)(32)))" This is a fairly straightforward translation of my Scala parser above, but without mutable state. What I've tried I'm trying to get as close to the Parsec solution as I can using Scalaz's state monad transformer, so instead of Parser[A] I'm working with StateT[Parser, Stream[Char], A]. I have a "solution" that allows me to write the following: import scala.util.parsing.combinator._ import scalaz._, Scalaz._ object ParenParser extends ExtraStateParsers[Stream[Char]] with RegexParsers { protected implicit def monadInstance = parserMonad(this) def paren: ESP[List[(Char, String)]] = (lift("(" ) ~> contents <~ lift(")")).flatMap { case (s, m) => get.flatMap( names => put(names.tail).map(_ => (names.head -> s) :: m) ) } def contents: ESP[(String, List[(Char, String)])] = lift("\\d+".r ^^ (_ -> Nil)) | rep1(paren).map( ps => ps.map(_.head._1).mkString -> ps.flatten ) def parse(s: String, names: Stream[Char]) = parseAll(paren.eval(names), s).map(_.toMap) } This works, and it's not that much less concise than either the mutable state version or the Parsec version. But my ExtraStateParsers is ugly as sin—I don't want to try your patience more than I already have, so I won't include it here (although here's a link, if you really want it). I've had to write new versions of every Parser and Parsers method I use above for my ExtraStateParsers and ESP types (rep1, ~>, <~, and |, in case you're counting). If I had needed to use other combinators, I'd have had to write new state transformer-level versions of them as well. Is there a cleaner way to do this? I'd love to see an example of a Scalaz 7's state monad transformer being used to thread state through a parser, but Scala 6 or Haskell examples would also be useful.

    Read the article

  • Regex to validate SMTP Responses?

    - by Alix Axel
    I'm writing a regular expression that can interactively validate SMTP responses codes, once the SMTP dialog is completed it should pass the following regex (some parentheses added for better readability): ^(220)(250){3,}(354)(250)(221)$ Or with(out) authentication: ^(220)(250)((334){2}(235))?(250){2,}(354)(250)(221)$ I'm trying to do rewrite the above regexes so that I can interactively check if the dialog is going as expected, otherwise politely send a QUIT command and close the connection saving bandwidth and time, but I'm having a hard time writing an optimal regex. So far I've managed to come up with: ^(220(250(334(235(250(354(250(221)?)?)?){0,})?){0,2})?)?$ Which, besides only matching authenticated connections, has some bugs... For instance, it matches: 220250334235250354250221 220250334334235250354250221 I've also tried the following modification: ^(220(250)?)?((334(235)?){2})?(250(354(250(221)?)?)?){0,}$ This one accepts non-authenticated responses but it fails to match 220250334 and wrongly matches 220250334334235250354250221 (at least 2 250 are needed before the 354 response code). Can someone help me out with this? Thanks in advance.

    Read the article

  • Insert multiple values using INSERT INTO

    - by Ben McCormack
    In SQL Server 2005, I'm trying to figure out why I'm not able to insert multiple fields into a table. The following query, which inserts one record, works fine: INSERT INTO [MyDB].[dbo].[MyTable] ([FieldID] ,[Description]) VALUES (1000,N'test') However, the following query, which specifies more than one value, fails: INSERT INTO [MyDB].[dbo].[MyTable] ([FieldID] ,[Description]) VALUES (1000,N'test'),(1001,N'test2') I get this message: Msg 102, Level 15, State 1, Line 5 Incorrect syntax near ','. When I looked up the help for INSERT in SQL Sever Management Studio, one of their examples showed using the "Values" syntax that I used (with groups of values in parentheses and separated by commas). The help documentation I found in SQL Server Management Studio looks like it's for SQL Server 2008, so perhaps that's the reason that the insert doesn't work. Either way, I can't figure out why it won't work.

    Read the article

  • Two '==' equality operators in same 'if' condition are not working as intended.

    - by Manav MN
    I am trying to establish equality of three equal variables, but the following code is not printing the obvious true answer which it should print. Can someone explain, how the compiler is parsing the given if condition internally? #include<stdio.h> int main() { int i = 123, j = 123, k = 123; if ( i == j == k) printf("Equal\n"); else printf("NOT Equal\n"); return 0; } Output: manav@workstation:~$ gcc -Wall -pedantic calc.c calc.c: In function ‘main’: calc.c:5: warning: suggest parentheses around comparison in operand of ‘==’ manav@workstation:~$ ./a.out NOT Equal manav@workstation:~$ EDIT: Going by the answers given below, is the following statement okay to check above equality? if ( (i==j) == (j==k))

    Read the article

  • preg_match problem

    - by Biroka
    I'm trying to get some stuff from a string in php. In RegexBuddy and Regular expression tester (firefox addon) it works good, but php gives me the following: Warning: preg_match() [function.preg-match]: Compilation failed: unmatched parentheses at offset 34 in D:\path\example.php on line 62 my pattern is "/.{4}_tmp\\([A-Za-z0-9.\\]*)\(([0-9]*)\) : (.*)/i" an example string: C:\Temp\browseide\projects\32\821C_tmp\SourceFiles\main.c(8) : error C2143: syntax error : missing ';' before 'for' what RegexBuddy gets: 821C_tmp\SourceFiles\main.c(8) : error C2143: syntax error : missing ';' before 'for' Group 1: SourceFiles\main.c Group 2: 8 Group 3: error C2143: syntax error : missing ';' before 'for'

    Read the article

  • How to evaluate a custom math expression in Python

    - by taynaron
    I'm writing a custom dice rolling parser (snicker if you must) in python. Basically, I want to use standard math evaluation but add the 'd' operator: #xdy sum = 0 for each in range(x): sum += randInt(1, y) return sum So that, for example, 1d6+2d6+2d6-72+4d100 = (5)+(1+1)+(6+2)-72+(5+39+38+59) = 84 I was using regex to replace all 'd's with the sum and then using eval, but my regex fell apart when dealing with parentheses on either side. Is there a faster way to go about this than implementing my own recursive parsing? Perhaps adding an operator to eval?

    Read the article

  • jQuery UI datepicker options as varialbe

    - by Desmond Liang
    I have a number of inputs on a page function as JQ UI datepicker. Each needs to have different settings. I want to minimize the JS so I save the settings as an attribute in each individual . <input type="text" class="datepicker" name="dateofbirth" id="dateofbirth" size="20" value="" options="{ dateFormat: 'yy-mm-dd',changeYear: true,yearRange: '1920:2010'}" /> <input type="text" class="datepicker" name="expdate" id="expdate" size="20" value="" options="{ yearRange: '2011:2020'}" /> I use js to load the options dynamically as the settings. $(document).ready(function(){ $(".datepicker").each(function(index){ $(this).datepicker("option" , $(this).attr('options')); }); }); datepicker is not functioning. If I empty the parentheses after $this.datepicker it works fine. I have also tried another way to assign settings. ("option",...) no dice.

    Read the article

  • Cannot find code completion and suggestions in Aptana 2.0

    - by Benjamin
    Greetings, I recently started using Aptana 1.5 to work on a site via FTP, developing pages in .php format with a mixture of HTML, CSS, jQuery, and -- naturally -- PHP. I develop a page with all of these elements together to save time, then separate them. One thing that I really liked about Aptana 1.5 was that it completed code (brackets, parentheses, etc) and suggested things as I typed. I upgraded to 2.0 today and cannot figure out for the life of me how to bring back all of these capabilities -- or remember if I had to do anything in 1.5 to get them. Here is a picture of what I am looking for Notice the suggestion for margin: and the "HTML, Js, CSS" up top. Any help with getting this to work in 2.0 would be greatly appreciated. Ever since installing 2.0, 1.5 has been throwing error messages and I can't seem to get my FTP settings to stay locked in.

    Read the article

  • Is there anyone out there that codes like I do?

    - by Jacob Relkin
    Hi, Some people have told me that my coding style is a lot different than theirs. I think I am somewhat neurotic when it comes to spacing and indenting though. Here's a snippet to show you what I mean: - ( void ) applicationDidFinishLaunching: ( UIApplication *) application { SomeObject *object = [ [ SomeObject alloc ] init ]; int x = 100 / 5; object.someInstanceVariable = ( ( 4 * x ) + rand() ); [ object someMethod ]; } Notice how I space out all of my brackets/parentheses, start curly braces on the same line, "my code has room to breathe", so to speak. So my questions are a) is this normal and b) What's your coding style?

    Read the article

  • Python nested dict comprehension with sets

    - by Jasie
    Can someone explain how to do nested dict comprehensions? >> l = [set([1, 2, 3]), set([4, 5, 6])] >> j = dict((a, i) for a in s for i, s in enumerate(l)) >> NameError: name 's' is not defined I would have liked: >> j >> {1:0, 2:0, 3:0, 4: 1, 5: 1, 6: 1} I just asked a previous question about a simpler dict comprehension where the parentheses in the generator function were reduced. How come the s in the leftmost comprehension is not recognized?

    Read the article

  • Use a template parameter in a preprocessor directive?

    - by Ranju V
    Is it possible to use a non-type constant template parameter in a preprocessor directive? Here's what I have in mind: template <int DING> struct Foo { enum { DOO = DING }; }; template <typename T> struct Blah { void DoIt() { #if (T::Doo & 0x010) // somecode here #endif } }; When I try this with something like Blah<Foo<0xFFFF>>, VC++ 2010 complains something about unmatched parentheses in the line where we are trying to use "#if". I am guessing the preprocessor doesn't really know anything about templates and this sort of thing just isn't in its domain. What say? Thanks!

    Read the article

  • Confused with conditional and logical operators - VB.net

    - by AgentRev
    I'm kind of new to VB.net, and since I just finished a C# course, the lack of parentheses creates a lot of confusion on how to write certain combinations of operators. The C# equivalent of the line I am trying to reproduce in VB would be like this : if ( (a == 0 && b != null) || (a == 1 && c != null) ) I'm have no idea how to write this in VB, I've tried many combinations of And, Or, AndAlso, OrElse, etc. but I can't achieve the desired result. I can't find any clear example of C# v.s. VB.net comparison on operators, and the notes I have aren't helpful either. Can someone help me figure this out?

    Read the article

  • C++ infix to postfix conversion for logical conditions

    - by Gopalakrishnan Subramani
    I want to evaluate one expression in C++. To evaluate it, I want the expression to be converted to prefix format. Here is an example wstring expression = "Feature1 And Feature2"; Here are possible ways. expression = "Feature1 And (Feature2 Or Feature3)"; expression = "Not Feature1 Or Feature3"; Here And, Or, Not are reserved words and parentheses ("(", )) are used for scope Not has higher precedence And is set next precedence to Not Or is set to next precedence to And WHITE SPACE used for delimiter. Expression has no other elements like TAB, NEWLINE I don't need arithmetic expressions. I can do the evaluation but can somebody help me to convert the strings to prefix notation?

    Read the article

  • preg_match basics question.

    - by Yo-L
    Hi all. Got some trouble with my preg_match. The code. $text = 'tel: 012 213 123. mobil: 0303 11234'; $regex_string = '/(tel|Tel|TEL)[\s|:]+(.+)[\.|\n]/'; preg_match($regex_string , $text, $match); And I get this result in $match[2] "012 213 123. mobil: 023 123 123" First question. I want the regex to stop at the .(dot) but it doesent. Can someone explain to why it isnt? Second question. preg_match uses () to get their match. Is it possible to skip the parentheses surrounding the different "Tel" and still get the same functionality? Thnx all stackoverflow is great :D

    Read the article

  • Is there anyone out there that codes like me?

    - by Jacob Relkin
    Hi, Some people have told me that my coding style is a lot different than theirs. I think I am somewhat neurotic when it comes to spacing and indenting though. Here's a snippet to show you what I mean: - ( void ) applicationDidFinishLaunching: ( UIApplication *) application { SomeObject *object = [ [ SomeObject alloc ] init ]; int x = 100 / 5; object.someInstanceVariable = ( ( 4 * x ) + rand() ); [ object someMethod ]; } Notice how I space out all of my brackets/parentheses, start curly braces on the same line, "my code has room to breathe", so to speak. So my questions are a) is this normal and b) What's your coding style?

    Read the article

  • Django dictionary in templates: Grab key from another objects attribute

    - by Jordan Messina
    I have a dictionary called number_devices I'm passing to a template, the dictionary keys are the ids of a list of objects I'm also passing to the template (called implementations). I'm iterating over the list of objects and then trying to use the object.id to get a value out of the dict like so: {% for implementation in implementations %} {{ number_devices.implementation.id }} {% endfor %} Unfortunately number_devices.implementation is evaluated first, then the result.id is evaluated obviously returning and displaying nothing. I can't use parentheses like: {{ number_devices.(implementation.id) }} because I get a parse error. How do I get around this annoyance in Django templates? Thanks for any help!

    Read the article

  • Scala methods ending in _=

    - by Alexey Romanov
    I seem to remember Scala treating methods ending in _= specially, so something like this: object X { var x: Int = 0; def y_=(n : Int) { x = n }} X.y = 1 should call X.y_=(1). However, in 2.8.0 RC1, I get an error message: <console>:6: error: value y is not a member of object X X.y = 1 ^ Interestingly, just trying to call the method without parentheses fails as well: scala> X.y_= 1 <console>:1: error: ';' expected but integer literal found. X.y_= 1 ^ Am I misremembering something which does actually exist or did I just invent it out of whole cloth?

    Read the article

  • Converting ObjC Blocks to C# Lambas

    - by Sam
    I need some help converting an Objective-C block to C#. Here is the source ObjC: NSDate* addYear = [_calendar dateByAddingComponents:((^{ NSDateComponents* components = [NSDateComponents new]; components.month = 12; return components; })()) toDate:now options:0]; Now I tried the following in C#: NSDate date = _calendar.DateByAddingComponents((() => { NSDateComponents components = new NSDateComponents(); components.Month = 12; return components; })(), now, NSCalendarOptions.None); To which I get the following compiler error: Expression denotes a 'anonymous method' where a 'method group' was expected. Removing the parentheses around the lambda yields Cannot convert 'lambda expression' to non-delegate type 'MonoTouch.Foundation.NSDateComponents'. What is the correct C# syntax? I need to retain the closures as there are a lot more in the code base that I am porting.

    Read the article

  • Function for averages of tuples in a dictionary

    - by Billy Mann
    I have a string, dictionary in the form: ('the head', {'exploded': (3.5, 1.0), 'the': (5.0, 1.0), "puppy's": (9.0, 1.0), 'head': (6.0, 1.0)}) Each parentheses is a tuple which corresponds to (score, standard deviation). I'm taking the average of just the first integer in each tuple. I've tried this: def score(string, d): for word in d: (score, std) = d[word] d[word]=float(score),float(std) if word in string: word = string.lower() number = len(string) return sum([v[0] for v in d.values()]) / float(len(d)) if len(string) == 0: return 0 When I run: print score('the head', {'exploded': (3.5, 1.0), 'the': (5.0, 1.0), "puppy's": (9.0, 1.0), 'head': (6.0, 1.0)}) I should get 5.5 but instead I'm getting 5.875. Can't figure out what in my function is not allowing me to get the correct answer.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >