regex

Perform multiple search-and-replaces on the colnames of a dataframe

天涯浪子 提交于 2021-01-27 13:20:46
问题 I have a dataframe with 95 cols and want to batch-rename a lot of them with simple regexes, like the snippet at bottom, there are ~30 such lines. Any other columns which don't match the search regex must be left untouched. **** Example: names(tr) = c('foo', 'bar', 'xxx_14', 'xxx_2001', 'yyy_76', 'baz', 'zzz_22', ...) **** I started out with a wall of 25 gsub()s - crude but effective: names(tr) <- gsub('_1$', '_R', names(tr)) names(tr) <- gsub('_14$', '_I', names(tr)) names(tr) <- gsub('_22$',

Regular Expression - Match String Not Preceded by Another String (JavaScript)

跟風遠走 提交于 2021-01-27 13:11:23
问题 I am trying to find a regular expression that will match a string when it's NOT preceded by another specific string (in my case, when it is NOT preceded by "http://"). This is in JavaScript , and I'm running on Chrome (not that it should matter). The sample code is: var str = 'http://www.stackoverflow.com www.stackoverflow.com'; alert(str.replace(new RegExp('SOMETHING','g'),'rocks')); And I want to replace SOMETHING with a regular expression that means "match www.stackoverflow.com unless it's

How to get part of string that matches with regular expression in SQL Server

一世执手 提交于 2021-01-27 12:31:56
问题 I am having a requirement where I need to parse a column value to get a work request number associated with it. For example, the column value may contain - "Worked on AB-0012589" or "AB-0012589 is completed" or whatever containing the work request number in it. ( Here AB-0012589 is the work request number ). Format of the work request number will not change. It will be in xx-xxxxxxx format, where two characters before the hyphen will be letters and the later part will be numbers . How can I

Require both letters and numbers - regExp

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 12:20:39
问题 I am trying to figure how to require both letters and numbers only without any other characters. So literally [a-z] and ( \d or [0-9] ) depending what is better way of doing it for numbers. So if I had a string that requires validation: $toValidate = 'Q23AS9D0APQQ2'; // It may start with letter or number, both cases possible. And then if I had validation for it: return /([a-z].*[0-9])|([0-9].*[a-z])/i.test($toValidate); I used an i flag here because it could be that user enters it lowercase

AWK negative regular expression with variable

假如想象 提交于 2021-01-27 12:02:46
问题 I am using awk in a bash script to compare two files to get just the not-matching lines. I need to compare all three fields of the second file (as one pattern?) with all lines of the first file: First file: chr1 9997 10330 HumanGM18558_peak_1 150 . 10.78887 18.86368 15.08777 100 chr1 628885 635117 HumanGM18558_peak_2 2509 . 83.77238 255.95094 250.99944 5270 chr1 15966215 15966638 HumanGM18558_peak_3 81 . 7.61567 11.78841 8.17169 200 Second file: chr1 628885 635117 chr1 1250086 1250413 chr1

Regex Comma or Comma Space or Space

牧云@^-^@ 提交于 2021-01-27 11:55:11
问题 My problem is the [,\s|,|\s] will match ", " as "," and leave a extra space So I do not get a match "Sat, Mon" with: (Thu|Fri|Sat)[,\s|,|\s](Mon|Tue) By matching on (Thu|Fri|Sat)[,\s|,|\s] I get a match on "Sat, " but the match.Value is on "Sat," (no space) Basically I want to also get a match on "Sat,Mon" "Sat, Mon" "Sat Mon" but not "SatMon" Thanks 回答1: (Thu|Fri|Sat)[,\s]\s*(Mon|Tue) This will allow comma or space and any additional space before Mon or Tue Your version was conflating the

Regex: How to match for exact length of multiple values?

喜你入骨 提交于 2021-01-27 11:52:39
问题 How can I use this pattern: [A-Za-z0-9]{10} to also match to other text sizes like: 12 and 25? I tried to make it like: [A-Za-z0-9]{10|12|25} ([A-Za-z0-9]){10}|{12}|{25} But it didn't succeed. 回答1: You need to use alternations if you need to match specific sized only: ^(?:[A-Za-z0-9]{10}|[A-Za-z0-9]{12}|[A-Za-z0-9]{25})$ If you want to match symbols within a range, say, from 10 to 25, you can use ^[A-Za-z0-9]{10,25}$ Also, [A-Za-z0-9] can be replaced with \p{Alnum} (see Java regex reference).

Regex: How to match for exact length of multiple values?

我的未来我决定 提交于 2021-01-27 11:50:29
问题 How can I use this pattern: [A-Za-z0-9]{10} to also match to other text sizes like: 12 and 25? I tried to make it like: [A-Za-z0-9]{10|12|25} ([A-Za-z0-9]){10}|{12}|{25} But it didn't succeed. 回答1: You need to use alternations if you need to match specific sized only: ^(?:[A-Za-z0-9]{10}|[A-Za-z0-9]{12}|[A-Za-z0-9]{25})$ If you want to match symbols within a range, say, from 10 to 25, you can use ^[A-Za-z0-9]{10,25}$ Also, [A-Za-z0-9] can be replaced with \p{Alnum} (see Java regex reference).

java regexp match morse code

自闭症网瘾萝莉.ら 提交于 2021-01-27 10:58:30
问题 I'm trying to test if the Morse code is legal. public static boolean isMorseCode( String code ){ return code.trim().matches("[+.|+\s|+-]"); } The Morse code line can begin with a . (known as Dit) and a - (known as Dah). It can have spaces in the line. 1 space between two specific codes like .- -. in this case the sum of codes which are only separated by one white space is a word. But it can also have 3 white spaces and then a new word begins. I'm using trim to exclude the fact that there

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

旧时模样 提交于 2021-01-27 10:46:00
问题 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