pattern-matching

Search for string allowing for one mismatch in any location of the string

送分小仙女□ 提交于 2019-12-17 10:37:41
问题 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 longer than 230,000 sequences. I need to look for each of my sequences of 25 characters, for example, (AGCCTCCCATGATTGAACAGATCAT). The genome is formatted as a continuous string, i.e.

Merge Multiple spaces to single space; remove trailing/leading spaces

喜夏-厌秋 提交于 2019-12-17 10:16:09
问题 I want to merge multiple spaces into single space(space could be tab also) and remove trailing/leading spaces. For example... string <- "Hi buddy what's up Bro" to "Hi buddy what's up bro" I checked the solution given at Regex to replace multiple spaces with a single space. Note that don't put \t or \n as exact space inside the toy string and feed that as pattern in gsub . I want that in R. Note that I am unable to put multiple space in toy string. Thanks 回答1: This seems to meet your needs.

XML schema restriction pattern for not allowing specific string

一曲冷凌霜 提交于 2019-12-17 10:02:37
问题 I need to write an XSD schema with a restriction on a field, to ensure that the value of the field does not contain the substring FILENAME at any location. For example, all of the following must be invalid: FILENAME ORIGINFILENAME FILENAMETEST 123FILENAME456 None of these values should be valid. In a regular expression language that supports negative lookahead, I could do this by writing /^((?!FILENAME).)*$ but the XSD pattern language does not support negative lookahead. How can I implement

Swift 2 - Pattern matching in “if”

折月煮酒 提交于 2019-12-17 07:21:36
问题 Recently I've saw the WWDC 2015 keynote from Apple. I also looked at some documentation but I can't find a "pattern matching in if" section, how it was written on one of the slides which they have shown. (68min 00sec video from Apple Events) Do you know what's this refers to? Or the syntax? 回答1: All it really means is that if statements now support pattern matching like switch statements already have. For example, the following is now a valid way of using if/else if/else statements to "switch

Does MySQL Regexp support Unicode matching

一笑奈何 提交于 2019-12-17 06:49:07
问题 Does anyone know if Mysql's regexp supports unicode? I've been doing some research and the majority of blogs etc. seem to indicate that there is a problem or its not supported. I'm wondering then is it best to use LIKE for unicode pattern matching and regexp for ASCII enhanced pattern matching? I Like the idea of being able to search for matches at the beginning or end of a string, but if regexp doesn't support unicode then this could be difficult if my text is unicode. 回答1: Does anyone know

POSIX character class does not work in base R regex

怎甘沉沦 提交于 2019-12-17 06:18:11
问题 I'm having some problems matching a pattern with a string of text in R . I'm trying to get TRUE with grepl when the text is something like "lettersornumbersorspaces y lettersornumbersorspaces". I'm using the following regex : ([:alnum:]|[:blank:])+[:blank:][yY][:blank:]([:alnum:]|[:blank:])+ When using the regex as follows to obtain the "address" it works at expected. regex <- "([:alnum:]|[:blank:])+[:blank:][yY][:blank:]([:alnum:]|[:blank:])+" address <- str_extract(fulltext, regex) I see

Match patterns in a matrix with a variable number of lines and count them in Matlab

佐手、 提交于 2019-12-14 03:56:14
问题 I have a matrix like this one: 8 8 8 2 2 2 6 6 7 7 7 1 1 6 6 6 6 8 8 0 6 8 8 1 6 6 There are fixed patterns that always repeat. I would like to detect them. They repeat according to these rules: Lines with 7 followed by lines with a number which can be (0, 1 or 2), followed by a 6 Lines with 8 followed by lines with a number which can be (0, 1 or 2), followed by a 6 For each one of the values on a single pattern detected (independently from the number of lines they are composed of), write in

Regex for matching last two parts of a URL

心已入冬 提交于 2019-12-14 03:49:59
问题 I am trying to figure out the best regex to simply match only the last two strings in a url. For instance with www.stackoverflow.com I just want to match stackoverflow.com The issue i have is some strings can have a large number of periods for instance a-abcnewsplus.i-a277eea3.rtmp.atlas.cdn.yimg.com should also return only yimg.com The set of URLS I am working with does not have any of the path information so one can assume the last part of the string is always .org or .com or something of

How do I compare x and y in F#?

孤街浪徒 提交于 2019-12-14 03:46:17
问题 I need help with the matching pattern that would compare 2 numbers. Something like that: let test x y = match x with | y when x < y -> printfn "less than" | y when x > y -> printfn "greater than" | _ -> printfn "equal" Somehow it falls to the "_" case when x is 0 and y is 200. What am I doing wrong here? 回答1: The problem with your code is that when you write: match x with | y when x < y -> (...) .. it means that you want to assign the value of x (the <expr> in match <expr> with ) to a new

Counting number of occurrences of word in java

*爱你&永不变心* 提交于 2019-12-14 02:43:55
问题 I want to count the number of occurrences of particular word in a source string. Let's say src="thisisamangoterrthisismangorightthis?" word="this" So what I am doing is, first search for index of word in src. It's at index 0. Now I am extracting the part from this index location to end of src. i.e., now src="isamangoterrthisismangorightthis?" and search for word again. But I am getting array out of bound exception. public static int countOccur(String s1, String s2) { int ans=0; int len1=s1