regex

How to concatenate files that have the same beginning of a name?

别说谁变了你拦得住时间么 提交于 2021-01-27 10:43:22
问题 I have a directory with a few hundred *.fasta files, such as: Bonobo_sp._str01_ABC784267_CDE789456.fasta Homo_sapiens_cc21_ABC897867_CDE456789.fasta Homo_sapiens_cc21_ABC893673_CDE753672.fasta Gorilla_gorilla_ghjk6789_ABC736522_CDE789456.fasta Gorilla_gorilla_ghjk6789_ABC627190_CDE891345.fasta Gorilla_gorilla_ghjk6789_ABC117190_CDE661345.fasta etc. I want to concatenate files that belong to the same species, so in this case Homo_sapiens_cc21 and Gorilla_gorilla_ghjk6789. Almost every species

Use dynamic (variable) string as regex pattern in dart

自古美人都是妖i 提交于 2021-01-27 10:18:52
问题 i am trying to pass variable in regex language DART `betweenLenth(val, field, [min = 4, max = 20]) { final RegExp nameExp = new RegExp(r'^\w{" + min + "," + max + "}$'); if (!nameExp.hasMatch(val)) return field + " must be between $min - $max characters "; }` thanks 回答1: A generic function to escape any literal string that you want to put inside a regex as a literal pattern part may look like escape(String s) { return s.replaceAllMapped(RegExp(r'[.*+?^${}()|[\]\\]'), (x) {return "\\${x[0]}";}

C++11常用新特性快速一览

二次信任 提交于 2021-01-27 09:57:05
转载自 https://blog.csdn.net/jiange_zh/article/details/79356417 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/jiange_zh/article/details/79356417 最近工作中,遇到一些问题,使用C++11实现起来会更加方便,而线上的生产环境还不支持C++11,于是决定新年开工后,在组内把C++11推广开来,整理以下文档,方便自己查阅,也方便同事快速上手。(对于异步编程十分实用的Future/Promise以及智能指针等,将不做整理介绍,组内使用的框架已经支持并广泛使用了,用的是自己公司参考boost实现的版本) 1. nullptr nullptr 出现的目的是为了替代 NULL。 在某种意义上来说,传统 C++ 会把 NULL、0 视为同一种东西,这取决于编译器如何定义 NULL,有些编译器会将 NULL 定义为 ((void*)0),有些则会直接将其定义为 0。 C++ 不允许直接将 void * 隐式转换到其他类型,但如果 NULL 被定义为 ((void*)0),那么当编译char *ch = NULL;时,NULL 只好被定义为 0。 而这依然会产生问题,将导致了 C++

Regex to find a multi line string that includes another string between lines

南楼画角 提交于 2021-01-27 08:16:47
问题 my first Q here. I have a log file that has multiple similar strings as hits: Region: AR OnlineID: Atl_Tuc ---Start--- FIFA 18 Legacy Edition ---END--- Region: FR OnlineID: jubtrrzz ---Start--- FIFA 19 Undertale Pro Evolution Soccer™ 2018 ---END--- Region: US OnlineID: Cu128yi ---Start--- KINGDOM HEARTS HD 1.5 +2.5 ReMIX ---END--- Region: RO OnlineID: Se116 ---Start--- Real Farm EA SPORTS™ FIFA 20 LittleBigPlanet™ 3 ---END--- Region: US OnlineID: CAJ5Y ---Start--- Madden NFL 18: G.O.A.T.

Python replace multiple strings while supporting backreferences

可紊 提交于 2021-01-27 07:59:04
问题 There are some nice ways to handle simultaneous multi-string replacement in python. However, I am having trouble creating an efficient function that can do that while also supporting backreferences. What i would like is to use a dictionary of expression / replacement terms, where the replacement terms may contain backreferences to something matched by the expression. e.g. (note the \1) repdict = {'&&':'and', '||':'or', '!([a-zA-Z_])':'not \1'} I put the SO answer mentioned at the outset into

Python replace multiple strings while supporting backreferences

。_饼干妹妹 提交于 2021-01-27 07:58:36
问题 There are some nice ways to handle simultaneous multi-string replacement in python. However, I am having trouble creating an efficient function that can do that while also supporting backreferences. What i would like is to use a dictionary of expression / replacement terms, where the replacement terms may contain backreferences to something matched by the expression. e.g. (note the \1) repdict = {'&&':'and', '||':'or', '!([a-zA-Z_])':'not \1'} I put the SO answer mentioned at the outset into

Regex split string by last occurrence of pattern

让人想犯罪 __ 提交于 2021-01-27 07:38:48
问题 I am using regex to split a string <book name> by <author name> into book and author names. re.split(r'\bby\b', text, 0, re.I) But problem arises when the book name contains the word "by" (e.g. Death by Blackhole by Tyson => ['Death', 'by Black...'] ) How do I split the string by the last occurrence of the search pattern? I have a hunch -/+ve look-ahead/behind could be useful here, but currently splitting hairs trying to construct the proper syntax. 回答1: You could use findall with a greedy .*

How to replace all occurences of a variable in a string using javascript?

穿精又带淫゛_ 提交于 2021-01-27 07:30:48
问题 I'm trying to replace all the occurrences of a variable in a string using javascript. This is not working.: var id = "__1"; var re = new RegExp('/' + id + '/g'); var newHtml = oldHtml.replace( re, "__2"); This is only replacing the first occurrence of id: var id = "__1"; var newHtml = oldHtml.replace( id,"__2"); What am I doing wrong here? Thanks 回答1: When you instantiate the RegExp object, you don't need to use slashes; the flags are passed as a second argument. For example: var id = "__1";

Getting form “action” from BeautifulSoup result

左心房为你撑大大i 提交于 2021-01-27 07:20:22
问题 I'm coding a Python parser for a website to do some job automatically but I'm not much into "re" module (regex) for Py and can't make it work. req = urllib2.Request(tl2) req.add_unredirected_header('User-Agent', ua) response = urllib2.urlopen(req) try: html = response.read() except urllib2.URLError, e: print "Error while reading data. Are you connected to the interwebz?!", e soup = BeautifulSoup.BeautifulSoup(html) form = soup.find('form', id='form_product_page') pret = form.prettify() print

Capture word between optional hyphens regex

半腔热情 提交于 2021-01-27 07:13:35
问题 I've following type of strings, abc - xyz abc - pqr - xyz abc - - xyz abc - pqr uvw - xyz I want to retrieve the text xyz from 1st string and pqr from 2nd string, `` (empty) from 3rd & pqr uvw . The 2nd hyphen is optional. abc is static string, it has to be there. I've tried following regex, /^(?:abc) - (.*)[^ -]?/ But it gives me following output, xyz pqr - xyz - xyz pqr uvw - xyz I don't need the last part in the second string. I'm using perl for scripting. Can it be done via regex? 回答1: