guys,
image attached in this post is from a web page.
i have a span to highlight text fragments in the web page using javascript. (green color span in the pic)
so when now when i select some content from the webpage, (highlighted in light-blue) how do i get the section selected from green color span?
in this case "been considered a...
In Python I can use re.findall(pattern, string) to return all non-overlapping matches of pattern in a string.
For example, in the following SVG path command:
import re
spam = "M317.0,169.7C311.1,170.5 285.7,146.8 300.7,178.57 L 321.4,175.01"
eggs = re.findall("([A-Za-z]|-?[0-9]+\.?[0-9]*(?:e-?[0-9]*)?)", spam)
print(eggs)
['M', '317.0'...
I am trying to write a comment matching rule in ANTLR, which is currently the following:
LINE_COMMENT
: '--' (options{greedy=false;}: .)* NEWLINE {Skip();}
;
NEWLINE : '\r'|'\n'|'\r\n' {Skip();};
This code works fine except in the case that a comment is the last characters of a file, in which case it throws a NoViableAlt exce...
Scala has a language feature to support disjunctions in pattern matching ('Pattern Alternatives').
x match {
case _: String | _: Int =>
case _ =>
}
However, I often need to trigger an action if the scrutinee satisfies PatternA and PatternB (conjunction.)
I created a pattern combinator '&&' that adds this capability. Three l...
Hey Haskellers,
Right now I'm studying the mtl library, trying to do some MonadTransformers of my own. I was checking the Control.Monad.State.StateT declaration, and across all the code, I see this syntax:
execStateT :: (Monad m) => StateT s m a -> s -> m s
execStateT m s = do
~(_, s') <- runStateT m s
return s'
I'm wondering, wh...
I have a set of case classes like this
abstract class Shape
case class Rectangle(width: Int, height: Int) extends Shape
case class Location(x: Int, y: Int, shape: Shape) extends Shape
case class Circle(radius: Int) extends Shape
case class Group(shape: Shape*) extends Shape
where basically Group is an array of shapes. I need t...
Hi guys,
I am bit new to c#, i am looking for a string matching pattern to do the following,
I have a string like this
The book will be showcased at a
reception in Number 11 Downing Street
and will be attended by key healthcare
i need to create a span tag to highlight some text fragments using startIndex and length,
for an...
i am looking for a longest common words c# implementation. Most of the samples i have came across are comparing character by character.
in otherwords,
string1 = access
string2 = advised
should return null output from the function
any sample codes?
...
I'm puzzled by how pattern matching works in F# for let. I'm using the Visual Studio 'F# interactive' window, F# version 1.9.7.8. Say we define a simple type:
type Point = Point of int * int ;;
and the try to pattern match against values of Point using let.
let Point(x, y) = Point(1, 2) in x ;;
fails with error FS0039: The value or...
I have a text like this
"You are advised to grant access to these settings only if you are sure you want to allow this program to run automatically when your computer starts. Otherwise it is better to deny access."
and i have 3 selections,
1. StartIndex = 8, Length = 16 // "advised to grant"
2. StartIndex = 16, Length = 33 //"to g...
I have been searching for a bit but can not locate any examples that demonstrate the usage of @_* while pattern matching case classes.
Below is an example of the kind of application I am referring to.
def findPerimeter(o: SomeObject): Perimeter = o match {
case Type1(length, width) =>
new Perimeter(0, 0, length, width)
case Type2(rad...
I have a table with few columns and one of the column is DockNumber. I have to display the docknumbers if they confirm to a particular format
First five characters are numbers followed by a - and followed by 5 characters. The last but one character should be a alpha.
12345-678V9
How can I check in SQL if the first 5 characters are nu...
Provide an example for the pseudo-regex: Match every url except those from example.com and example2.com according to the PHP regexp syntax.
Here is what I have so far, but it doesn't work:
$patternToMatch = "@https?://[^(example.com|example2.com)]\"*@i";
...
First, a little background. I have strings that resemble the following:
((Foo.Bar.StartsWith("A")) &&
(Foo.Bar.EndsWith("B")))
And I'm trying to reformat these to look like this:
((Foo.Any(Bar.StartsWith("A"))) &&
(Foo.Any(Bar.EndsWith("B"))))
Side Note: The parts following the .Bar may sometimes not include (), like .Bar...
Just to clarify, when I say multiple assigment, parallel assignment, destructuring bind I mean the following pattern matching gem
scala> val (x,y) = Tuple2("one",1)
x: java.lang.String = one
y: Int = 1
which assigns "one" to x and 1 to y.
I was trying to do
val (x,y) = "a b".split()
I was expecting that scala would attempt to patt...
I have a function of the form
'a -> ('a * int) list -> int
let rec getValue identifier bindings =
match bindings with
| (identifier, value)::tail -> value
| (_, _)::tail -> getValue identifier tail
| [] -> -1
I can tell that identifier is not being bound the way I would like it to and is acting as a variable within the match...
Hi! As a beginner in Ocaml, I have this current working code:
...
let ch_in = open_in input_file in
try
proc_lines ch_in
with End_of_file -> close_in ch_in;;
Now I would like to add error handling for non-existing input files, I wrote this:
let ch_in = try Some (open_in input_file) with _ -> None in
match ch_in with
| Some x -> t...
In php, I have used preg_match_all() to find keywords (using the format %keyword%) in a string, which works wonderfully and returns an array of all found keywords.
What I would like to do, is do the same thing using jQuery or javascript. I have tried using the filter() function, and it kind of works. But I think I am missing somethin...
I'm trying to come up with a way to query the values in two different columns in the same table where the result set will indicate instances where the value of columnB doesn't contain the value of columnA.
For example, my "Nodes" table contains columns "NodeName" and "DNS".
The values should look similar to the following:
NodeName D...
I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite) I am not sure how large the genome is but much more that 230,000 sequences.
I need to look for each of my sequences of 25 characters example(AGCCTCCCATGATTGAACAG...