pattern-matching

Whole word matching with unexpected insertion in data

China☆狼群 提交于 2020-01-02 07:17:08
问题 I have string consider my $string = 'String need to be evaluated'; in $string I'm searching evaluated or any other word. problem is their may be insertion of some tags in string eg. Str<data>ing need to be eval<data>ua<data>ted which is unexpected. In this case how could I search for the words? here is the code I tried: my $string = 'Text to be evaluated'; my $string2 = "Te<data>xt need to be eval<data2>ua<data>ted"; # patten to match $pattern = "evaluated"; @b = split('',$pattern); for my $i

Counting the number of substrings

吃可爱长大的小学妹 提交于 2020-01-02 04:00:29
问题 I would like to ask if there is an algorithm for counting the number of discrete occurencies of a substring in a string in O(n) time. 回答1: [EDIT 17/11/2013: Count the leaf nodes. Thanks Vinicius Pinto!] You can build a suffix tree on the text in linear time. Then, search for your substring in the suffix tree; when you find it, count the number of leaf nodes beneath the matching node. This is O(m + k) for a substring of length m that appears k times (add an n term for building the suffix tree)

What is wrong with my regex Pattern to find recurring cycles in Python?

試著忘記壹切 提交于 2020-01-01 14:29:48
问题 I want to match any string that has a recurring cycle. Like in this data: 3333333333333333333333333333333333333333 / 1 digit cycle(3) 1666666666666666666666666666666666666666 / 1 digit cycle(6) 1428571428571428571428571428571428571428 / 6 digit cycle(142857) 1111111111111111111111111111111111111111 / 1 digit cycle(1) 0909090909090909090909090909090909090909 / 2 digit cycle(09) 0834522467546323545411673445234655345222 / no cycle 0769230769230769230769230769230769230769 / 6 digit cycle(769230)

What is wrong with my regex Pattern to find recurring cycles in Python?

為{幸葍}努か 提交于 2020-01-01 14:29:04
问题 I want to match any string that has a recurring cycle. Like in this data: 3333333333333333333333333333333333333333 / 1 digit cycle(3) 1666666666666666666666666666666666666666 / 1 digit cycle(6) 1428571428571428571428571428571428571428 / 6 digit cycle(142857) 1111111111111111111111111111111111111111 / 1 digit cycle(1) 0909090909090909090909090909090909090909 / 2 digit cycle(09) 0834522467546323545411673445234655345222 / no cycle 0769230769230769230769230769230769230769 / 6 digit cycle(769230)

Surjectivity check when return type is sealed

自闭症网瘾萝莉.ら 提交于 2020-01-01 09:50:40
问题 Scala can warn when pattern match on a sealed type is not exhaustive, however can we check that a function returns all cases when the return type is sealed? For example, consider the following ADT sealed trait Foo case object Bar extends Foo case object Qux extends Foo Then function f: Foo => String on the algebraic data type Foo def f(x: Foo): String = x match { case Bar => "bar" } raises warning match may not be exhaustive. It would fail on the following input: Qux def f(x: Foo) = x match {

State transition table for aho corasick algorithm

喜你入骨 提交于 2020-01-01 06:54:34
问题 Please help me to understand the construction of state transition table for more than one patterns in the Aho-Corasick algorithm. Please give a simple and detailed explanation so that I could understand. I am following this paper and here is the animation for that. Thanks. 回答1: Phase 1 Creating the keyword tree : Starting at the root, follow the path labeled by chars of P i If the path ends before P i , continue it by adding new edges and ... nodes for the remaining characters of P Store

matching text in quotes (newbie)

99封情书 提交于 2020-01-01 03:35:12
问题 I'm getting totally lost in shell programming, mainly because every site I use offers different tool to do pattern matching. So my question is what tool to use to do simple pattern matching in piped stream. context: I have named.conf file, and i need all zones names in a simple file for further processing. So I do ~$ cat named.local | grep zone and get totally lost here. My output is ~hundred or so newlines in form 'zone "domain.tld" {' and I need text in double quotes. Thanks for showing a

Haskell pattern match “diverge” and ⊥

好久不见. 提交于 2020-01-01 01:41:06
问题 I'm trying to understand the Haskell 2010 Report section 3.17.2 "Informal Semantics of Pattern Matching". Most of it, relating to a pattern match succeeding or failing seems straightforward, however I'm having difficulty understanding the case which is described as the pattern match "diverging". I'm semi-persuaded it means that the match algorithm does not "converge" to an answer (hence the match function never returns). But if doesn't return, then, how can it return a value, as suggested by

How to replace a user input in regular expression?

前提是你 提交于 2019-12-31 05:58:17
问题 I will use simple codes to describe my situation. For example, here are the codes: using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\b(?!non)\w+\b"; string input = "Nonsense is not always non-functional."; foreach (Match match in Regex.Matches(input, pattern, RegexOptions.IgnoreCase)) Console.WriteLine(match.Value); } } Now, I would like to replace the "non" with a user input. Let say it's called "UserInput" and the

How to replace a user input in regular expression?

陌路散爱 提交于 2019-12-31 05:58:04
问题 I will use simple codes to describe my situation. For example, here are the codes: using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"\b(?!non)\w+\b"; string input = "Nonsense is not always non-functional."; foreach (Match match in Regex.Matches(input, pattern, RegexOptions.IgnoreCase)) Console.WriteLine(match.Value); } } Now, I would like to replace the "non" with a user input. Let say it's called "UserInput" and the