pattern-matching

Why doesnt work regex

本秂侑毒 提交于 2019-12-25 01:46:44
问题 Code Example 14> case re:run("5162754", "/^\d+$/") of {match, _} -> ok end. ** exception error: no case clause matching nomatch 15> case re:run(<<"5162754">>, "/^\d+$/") of {match, _} -> ok end. ** exception error: no case clause matching nomatch Why doesn't it match? 回答1: Two things: The regular expression you pass to re:run shouldn't be surrounded by / . In other languages, you write a regexp inside / signs, but in Erlang, regexps are always written as strings, and thus no / signs are

RegEx to split string based on operators and retain operator in answer

我的梦境 提交于 2019-12-25 01:45:16
问题 I want to split string based on few operands. For e.g. String : a&&(b||c) ANS : String[] {a,&&,(,||,c,)} IS it possible with java RegEx? If yes then how? I tried with [&&||()] regEx , but its not giving desired output. and even I am not sure how to retain operators. EDIT: And what if we have & and | instead of && and || ? 回答1: You could split by: (?<![&|])(?=[&|])|(?<=[&|])(?![&|]) (?<![&|])(?=[&|]) means "any inter-char that isn't preceded by & or | but that is followed by & or | "; On the

Parsing curl response with Java

谁说我不能喝 提交于 2019-12-24 22:52:13
问题 Before writing something like "why don't you use Java HTTP client such as apache, etc" , I need you to know that the reason is SSL. I wish I could, they are very convenient, but I can't. None of the available HTTP clients support GOST cipher suite, and I get handshake exception all the time. The ones which do support the suite, doesn't support SNI (they are also proprietary) - I'm returned with a wrong cert and get handshake exception over and over again. The only solution was to configure

Comparing data using lookup and output only longest phrase in the data using python?

我怕爱的太早我们不能终老 提交于 2019-12-24 22:32:20
问题 I have a csv which contains "KKR" map to "MBI" data. I want to perform a lookup from a user given data to extract the longest matched phrase from KKR (ignore small phrase if it contains words of long phrase) #os.chdir("kkr_lookup") data = pd.read_csv("KKR_MBI_MAP.csv") dfData = pd.DataFrame(data) dfVerbatim = pd.DataFrame() dataVerbatim = {'verbatim': ['She experienced skin allergy and hair loss after using it for 2-3 weeks']} dfVerbatim = pd.DataFrame(dataVerbatim, columns = ['verbatim'])

python grep reverse matching

我与影子孤独终老i 提交于 2019-12-24 19:47:07
问题 I would like to build a small python script that basicaly does the reverse of grep. I want to match the files in a directory/subdirectory that doesn't have a "searched_string". So far i've done that: import os filefilter = ['java','.jsp'] path= "/home/patate/code/project" for path, subdirs, files in os.walk(path): for name in files: if name[-4:] in filefilter : print os.path.join(path, name) This small script will be listing everyfiles with "java" or "jsp" extension inside each subdirectory,

Regex get html input value dynamic tag position

十年热恋 提交于 2019-12-24 19:13:54
问题 I've question about how to get value from input html when the tag position is dynamic. This is the example input: <input type="text" autocomplete="" name="confirmedEmailAddress" id="emailaddress" maxlength="60" value="fname.lname@gmail.com" class="txt-box txtbox-m " aria-describedby="" aria-required="true" disabled="disabled"> <input type="text" autocomplete="" value="fname.lname@gmail.com" name="confirmedEmailAddress" id="emailaddress" maxlength="60" class="txt-box txtbox-m " aria

OCaml pair int with char list

放肆的年华 提交于 2019-12-24 19:05:19
问题 I'm working with a function with the prototype remaining thelist that needs to take on the signature val remaining : char list -> int * char list = <fun> . I'm new to Ocaml and I do not understand how to make an Ocaml function take in only a list and output both an int and a list. This is the code I'm currently working with. let rec remaining thelist= match thelist with | [] -> [] | [x] -> [x] | x::y::t1 -> if x='a' then remaining (y::t1) else thelist;; match thelist with | [] -> 0 | x::t1 ->

How can I pattern match a tuple containing a &mut enum and use the enum in the match arm?

落爺英雄遲暮 提交于 2019-12-24 18:34:49
问题 How can the code below be made to compile? It seems perfectly safe, but can't convince the compiler that it is. The version matching *self gives the error: cannot move out of borrowed content on the line of the match The version matching self gives: use of moved value: *self enum Foo { Foo1(u32), Foo2(i16), } impl Foo { fn bar(&mut self, y: u32) -> (u32, &mut Foo) { match (*self, y) { (Foo::Foo1(ref mut a), b) if (b == 5) => { print!("is five"); *a = b + 42; (b, self) } (Foo::Foo2(ref mut a),

Java : How to find string patterns in a LARGE binary file?

狂风中的少年 提交于 2019-12-24 18:02:40
问题 I'm trying to write a program that will read a VERY LARGE binary file and try to find the occurrence of 2 different strings and then print the indexes that matches the patterns. For the example's sake let's assume the character sequences are [H,e,l,l,o] and [H,e,l,l,o, ,W,o,r,l,d] . I was able to code this for small binary files because I was reading each character as a byte and then saving it in an Arraylist . Then starting from the beginning of the Arraylist , I was comparing the byte

Java : How to find string patterns in a LARGE binary file?

风流意气都作罢 提交于 2019-12-24 18:02:34
问题 I'm trying to write a program that will read a VERY LARGE binary file and try to find the occurrence of 2 different strings and then print the indexes that matches the patterns. For the example's sake let's assume the character sequences are [H,e,l,l,o] and [H,e,l,l,o, ,W,o,r,l,d] . I was able to code this for small binary files because I was reading each character as a byte and then saving it in an Arraylist . Then starting from the beginning of the Arraylist , I was comparing the byte