pattern-matching

Print out the string that matched my regular expression in java?

落爺英雄遲暮 提交于 2019-12-08 09:31:01
问题 Possible duplicate: Print regex matches in java I am using Matcher class in java to match a string with a particular regular expression which I converted into a Pattern using the Pattern class. I know my regex works because when I do Matcher.find(), I am getting true values where I am supposed to. But I want to print out the stings that are producing those true values (meaning print out the strings that match my regex) and I don't see a method in the matcher class to achieve that. Please do

Case classes matching in Scala

喜你入骨 提交于 2019-12-08 09:25:52
问题 I want to have this comparison function that matches two case classes, but it's a bit verbose. Leafs are always in the sorted order in the List. abstract class CodeTree case class Fork(left: CodeTree, right: CodeTree, chars: List[Char], weight: Int) extends CodeTree case class Leaf(char: Char, weight: Int) extends CodeTree def sortCodeTreeFun(x: CodeTree, y: CodeTree) = { (x, y) match { case (x1: Leaf, y1: Leaf) => true case (x1: Fork, y1: Leaf) => x1.weight < y1.weight case (x1: Leaf, y1:

Understanding the Haskell as-pattern

空扰寡人 提交于 2019-12-08 08:49:01
问题 I'm reading through Real World Haskell, and am trying to understand the as-pattern. From the book (Chapter 4): suffixes :: [a] -> [[a]] suffixes xs@(_:xs') = xs : suffixes xs' suffixes _ = [] The book explains the @ symbol thus, "...bind the variable xs to the value that matches the right side of the @ symbol." I'm having trouble understanding this explanation. Supposing I call suffixes "hello" Explicitly, what would the above line with the @ do to this (on the first iteration)? I know what

I need search a pattern in a header line of my file and concatenates the next line with Perl

主宰稳场 提交于 2019-12-08 08:43:11
问题 My multi-fasta archive is in this format: >miRNA65 dvex2345 CGATGCTAGATGCTATGACAACGATGCCTCG-G >miRNA60 dvex1234 T-TAA-ACTCATCATCATCATACTCATCATCATCATCAGCATATTAACAAG >miRNA65 dvex2345 T-TAA-ACTTATCATCATCATACTCATCATCATCATCAGCATATTAACAAG I am new in Perl and I need to search the equals '> lines' and concatenate the next line to join the sequence. I'm expecting the following output for the above file: >miRNA60 dvex1234 T-TAA-ACTCATCATCATCATACTCATCATCATCATCAGCATATTAACAAG >miRNA65 dvex2345 T-TAA

Automated website categorization

会有一股神秘感。 提交于 2019-12-08 08:20:34
I want to create this engine which will categorize websites based on their meta keyword attribute. Extracting of keyword from the website has been easy as well as connecting with the database. The problem that I am facing is the algorithm how to to match the 'keyword' extracted from the website with the predefined set of strings. Please help me. I am using PHP scripts to implement this. //say I have $pattern as the meta keyword extracted from web page (ignore the syntax – please me) $pattern=<news, current affairs, breaking news, sports, entertainment, daily news, local news> // and set of

'sed' replace last patern and delete others pattern

随声附和 提交于 2019-12-08 05:42:17
问题 I want to replace only the last string "delay" by "ens_delay" in my file and delete the others one before the last one: Input file: alpha_notify_teta='' alpha_notify_check='YES' text='CRDS' delay='' delay='' delay='' textfileooooop='' alpha_enable='YES' alpha_hostnames='' alpha_orange='YES' alpha_orange_interval='300' alpha_notification_level='ALL' expression='YES' delay='9' textfileooooop='' alpha_enable='YES' alpha_hostnames='' Output file: (expected value) alpha_notify_teta='' alpha_notify

Regex remove all occurrences of multiple characters in a string

无人久伴 提交于 2019-12-08 05:32:03
问题 In my PostgreSQL I want to replace all characters (;<>) occurrences in a string. My query: update table_name set text = regexp_replace(text, '/[(;<>)]+/g', ''); I think my regexp is wrong. Can anyone help me out with it? 回答1: Use the much faster translate() for this simple case: UPDATE tbl SET text = translate(text, '(;<>)', ''); Every character in the second parameter that has no counterpart in the third parameter is replaced with nothing. The regular expression solution could look like this

Pattern matching on a GADT fails

。_饼干妹妹 提交于 2019-12-08 03:43:45
问题 I was playing around a bit more with ReasonML and found pattern matching on type t from the following example to not be working with the error Error: This pattern matches values of type t(float) but a pattern was expected which matches values of type t(int) Type float is not compatible with type int type t('a) = | One: t(int) | Two: t(float); let x = fun | One => None | Two => None; Now on some level this makes sense to me if this was about the return type of a function. I found an answer (I

Is True = False? Understanding binding and pattern matching [duplicate]

元气小坏坏 提交于 2019-12-08 03:27:59
问题 This question already has answers here : What does `let 5 = 10` do? Is it not an assignment operation? (3 answers) Closed last year . A friend of us is teaching to us the basics of functional programming in Haskell, and he started to write the rarest thing I ever saw: He started with something not so amazing, but pretty cool: (x,y) = (10,20) (z:zs) = 0 : [1..] and shows in the prelude: prelude> x 10 prelude> z 0 prelude> takeN 3 zs [1,2,3] so far, so good... I didn't know you could bind the

How to read a file and extract data between multiline patterns?

寵の児 提交于 2019-12-08 03:22:14
问题 I have a file from which I need to extract one piece of data, delimited by (possibly) multiline fixed patterns some data ... [my opening pattern is here and can be multiline] the data I want to extract [my ending pattern which can be multiline as well] ... more data These patterns are fixed in the sense that the content is always the same, except that it can include new lines between words. The solution would be simple if I had the assurance that my pattern will be predictably formatted but