regex

batch renaming of files with perl expressions

僤鯓⒐⒋嵵緔 提交于 2021-01-27 05:27:59
问题 This should be a basic question for a lot of people, but I am a biologist with no programming background, so please excuse my question. What I am trying to do is rename about 100,000 gzipped data files that have existing name of a code (example: XG453834.fasta.gz). I'd like to name them to something easily readable and parseable by me (example: Xanthomonas_galactus_str_453.fasta.gz). I've tried to use sed , rename , and mmv , to no avail. If I use any of those commands on a one-off script

batch renaming of files with perl expressions

纵然是瞬间 提交于 2021-01-27 05:27:27
问题 This should be a basic question for a lot of people, but I am a biologist with no programming background, so please excuse my question. What I am trying to do is rename about 100,000 gzipped data files that have existing name of a code (example: XG453834.fasta.gz). I'd like to name them to something easily readable and parseable by me (example: Xanthomonas_galactus_str_453.fasta.gz). I've tried to use sed , rename , and mmv , to no avail. If I use any of those commands on a one-off script

Match a pattern only once

删除回忆录丶 提交于 2021-01-27 04:14:17
问题 I have a string foo-bar-bat.bla I wish to match only foo My flawed pattern matches both foo and bar \w+(?=-.*\.bla) How do I discard bar ? Or maybe even better, how could I stop matching stuff after foo ? 回答1: You could use the following pattern (as long as your strings are always formatted the way you said) : ^\w+(?=-.*\.bla) Edit live on Debuggex The ^ sign matches the beginning of the string. And thus will take the very first match of the string. The ?= is meant to make sure the group

Whole-word matching with regex.h

随声附和 提交于 2021-01-27 04:12:37
问题 I want a C++ regex that matches "bananas" or "pajamas" but not "bananas2" or "bananaspajamas" or "banana" or basically anything besides those exact two words. So I did this: #include <regex.h> #include <stdio.h> int main() { regex_t rexp; int rv = regcomp(&rexp, "\\bbananas\\b|\\bpajamas\\b", REG_EXTENDED | REG_NOSUB); if (rv != 0) { printf("Abandon hope, all ye who enter here\n"); } regmatch_t match; int diditmatch = regexec(&rexp, "bananas", 1, &match, 0); printf("%d %d\n", diditmatch, REG

How to find number of matches to regexp in perl6?

妖精的绣舞 提交于 2021-01-27 04:11:32
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

Splitting string into array of words using Regular Expressions

感情迁移 提交于 2021-01-27 04:11:07
问题 I'm trying to split a string into an array of words, however I want to keep the spaces after each word. Here's what I'm trying: var re = /[a-z]+[$\s+]/gi; var test = "test one two three four "; var results = test.match(re); The results I expect are: [0]: "test " [1]: "one " [2]: "two " [3]: "three " [4]: "four " However, it only matches up to one space after each word: [0]: "test " [1]: "one " [2]: "two " [3]: "three " [4]: "four " What am I doing wrong? 回答1: Consider: var results = test

How to find number of matches to regexp in perl6?

六眼飞鱼酱① 提交于 2021-01-27 04:10:44
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

How to find number of matches to regexp in perl6?

不羁的心 提交于 2021-01-27 04:10:07
问题 In Perl 5 we can write my @things = $text =~ /thing/g; And $things in scalar context is number of non-overlapping occurrences of substring thing in string $text . How to do this in Perl 6? 回答1: You can do it like this: my $text = 'thingthingthing' my @things = $text ~~ m:g/thing/; say +@things; # 3 ~~ matches the left side against the right side, m:g makes the test return a List[Match] containing all the results. 回答2: I found solution on RosettaCode . http://rosettacode.org/wiki/Count

Regex to wrap text with tags [duplicate]

爱⌒轻易说出口 提交于 2021-01-27 03:58:25
问题 This question already has answers here : Find a string of text in an element and wrap some span tags round it (6 answers) Closed last year . I need a JavaScript regex to wrap "#hashtags" with <span> tags Example: Before: "I need #help, please. #Thanks" After: "I need <span> #help </span> , please. <span> #Thanks </span> " Currently, /#\w*\b/g finds all of the #hashtags but how do I wrap them in span tags? Thanks! 回答1: This works - str = "I need #help, please. #Thanks" str = str.replace(/(\#[a

Regex to wrap text with tags [duplicate]

痴心易碎 提交于 2021-01-27 03:57:32
问题 This question already has answers here : Find a string of text in an element and wrap some span tags round it (6 answers) Closed last year . I need a JavaScript regex to wrap "#hashtags" with <span> tags Example: Before: "I need #help, please. #Thanks" After: "I need <span> #help </span> , please. <span> #Thanks </span> " Currently, /#\w*\b/g finds all of the #hashtags but how do I wrap them in span tags? Thanks! 回答1: This works - str = "I need #help, please. #Thanks" str = str.replace(/(\#[a