pattern-matching

Pattern.compile() throws exception

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 04:56:33
问题 I am using a regex to find if a string is present in a book page. Below is the code for the same. String regex = ".*\\b.{0}" + searchText + ".{0}.*\\b"; Pattern pattern = Pattern.compile(regex); pattern.matcher("This is the text area where I am trying to look for the particular text, which is in the variable searchText. This text will have the string (222M) as part of this string. The find method should give me a true result even if I don't enter the closing brakect of the word. This is a

Regex and textmatching issue

▼魔方 西西 提交于 2019-12-12 04:54:30
问题 I am doing some basic text matching in Postgres 9.3.5.0. Here is my code so far: Select text from eightks WHERE other_events = true and keywordRegexs = [\y(director and member \s+ and resigned)\y/ix]; I am getting the following errors psql:test3.sql:3: invalid command \y(director psql:test3.sql:5: ERROR: syntax error at or near "[" LINE 3: keywordRegexs = [ I am trying to find documents which contain those exact phrases. 回答1: The regular expression match operator in Postgres is ~ . The case

Python Pandas TypeError: first argument must be string or compiled pattern

ε祈祈猫儿з 提交于 2019-12-12 04:53:36
问题 I am sorry for the super easy question, but I can't make it work I am cleaning data and want to add a flag, if the name (which is seperate into two columns First and Last Name) is wrong. I established multiple patterns, but for now I was working with seperate statements, can I merge all of those statements into one? pattern = "\?" match = incremental['First_Name'].str.contains(pattern) | incremental['Last_Name'].str.contains(pattern) incremental['Name_Flag'] = np.where(match, 'Y', '') pattern

Matching a pattern with sed and getting an integer out at the same time

浪子不回头ぞ 提交于 2019-12-12 04:29:54
问题 I have an xml file with these lines (among others): #Env=DEV2,DEV3,DEV5,DEV6 #Enter your required DEV environment after the ENV= in the next line: Env=DEV6 I need to: Verify that the text after ENV= is of the pattern DEV{1..99} extract the number (in this case, 6) from the line ENV=DEV6 to some environment variable I know a bit of awk and grep, and can use those to get the number, but I'm thinking of Sed, which I'm told matches patterns nicer than awk and takes less time. Also, I'm concerned

Find the longest substring in two genomic sequence

拥有回忆 提交于 2019-12-12 04:09:48
问题 I have two sequences AAAAAAAAAGAAAAGAAGAAG, AAAGAAG. The correct answer is AAGAAG. But my code gives AA. There will also be times when two strings will be in this order AAAGAAG, AAAAAAAAAGAAAAGAAGAAG. Here is my code `def longestSubstringFinder(string1, string2): string1=string1.strip() string2=string2.strip() answer = "" len1=len(string1) len2=len(string2) if int(len1)>1 and int(len2)>1: for i in range(1,len1,1): match = "" for j in range(len2): if len1>len2: if i+j<len1 and (string1[i+j]=

Search for words ending with 'ing' from a text file in perl

落花浮王杯 提交于 2019-12-12 03:51:30
问题 I have a text file , lets call it file1.txt : cats and dogs are running around | john loves mary | I am swimming | I am trying to build a program which looks for the words ending with 'ing' and prints CC beside them on the same file or to a different output.txt file. Desired Output cats and dogs are running CC around | john loves mary | I am swimming CC | I went through the available articles in the forum and tried building the following code ,however it gives me an arbitrary result with

Haskell - finding smallest Element in list

爷,独闯天下 提交于 2019-12-12 03:35:20
问题 I have a function that gets a List and has to return the smallest Element of it. Unfortunately I keep getting the issue: Parse error in pattern: minim What could I have done wrong? minim :: [Int] -> Int minim [] = 0 minim [x] = x minim x:xs = min x (minim xs) min :: Int -> Int -> Int min a b | a > b = b | a < b = a 回答1: If you want to solve it the most Haskell way. I would solve it as such: -- Does not work for empty lists (so maybe needs to be wrapped in some logic) foldr1 min [-3,1,2,3] --

Pattern matching AST nodes in Rascal

不问归期 提交于 2019-12-12 03:26:14
问题 I have the following AST definition: data Exp = app(Exp fun, Exp body) | var(str name) | nat(int nat) | func(list[str] formal, Exp body) | cond(Exp cond, Exp then, list[tuple[Exp,Exp]] elifs, Exp otherwise) | let(list[str] vars, list[Exp] exps, Exp body) | seq(Exp lhs, Exp rhs) | mul(Exp lhs, Exp rhs) | div(Exp lhs, Exp rhs) | md(Exp lhs, Exp rhs) | add(Exp lhs, Exp rhs) | sub(Exp lhs, Exp rhs) | eq(Exp lhs, Exp rhs) | gt(Exp lhs, Exp rhs) | lt(Exp lhs, Exp rhs) | geq(Exp lhs, Exp rhs) | leq

Searching for multiple lines including a blank one in shell script

为君一笑 提交于 2019-12-12 02:48:04
问题 I am using the following command to find a pattern spanning multiple lines and replacing it with a blank line: sed -n '1h; 1!H; ${ g; s/<Pattern1>\n<pattern2> //g p }' <file-name> For example, to find the pattern John Doe in a file test.txt which contains the following entries: Mary John Doe Simon Henry I would use the command: sed -n '1h; 1!H; ${ g; s/John\nDoe //g p }' test.txt However, I can't seem to make this command work for a pattern which has the second line as a blank, i.e. using the

How can I detect multiple occurrence of of an object in an Image

怎甘沉沦 提交于 2019-12-12 02:32:37
问题 Hi new to OpenCV and I am using JavaCV plugin in Unity to detect floorplan. I want to detect the position of windows, doors and few other objects in the floorplan image. First I used template matching for detection, but later I figured out it wont work if object is placed in different orientation or size of object is mismatched. I am using the device camera to capture the image hence image may get a little skewed hence I abandoned this technique. Following is the reference image and the