I have a string which has repeated values "There are 14 no of pigs and 11 no of cows and many more".Here in this string I want to find the substring starting with number and ending with animal names and replace with some other string.  tried with this. But it selects complete string (\b\d+.* (pig|cow|chicken)s?\b) And not the individual substrings.
3211
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM J0000010: Project name: E:\foo.pf J0000011: Job name: MBiek Direct Mail Test J0000020: Document 1 - Completed successfully  I'm trying to extract pieces from it using regex. In this case, I want to grab everything after Project Name up to the part where it says J0000011: (the 11 is going to be a different number every time). Here's the regex I've been playing with: Project name:\s+(.*)\s+J[0-9]{7}:  The problem is that it doesn't stop until it hits the J0000020: at the end. How do I make the regex stop at the first occurrence of J[0-9]{7}?
70196
What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want to organize them neatly.  I kind of want to collect all substituend-substituent pairs in a file dictionary.txt in an easy-to-manage way, since I need to replace a lot of stuff, say like:  "yes"      : "no" "stop"     : "go, go, go!" "wee-ooo"  : "ooooh nooo!" "gooodbye" : "hello"  "high"     : "low" "why?"     : "i don't know"   Now I want to apply these substitutions in some file novel.txt.  Then I want to run magiccommand --magicflags dictionary.txt novel.txt so that all instances of yes in novel.txt are replaced by no (so even Bayesian would be replaced by Banoian) and all instances of goodbye in novel.txt would be replaced by hello and so forth.  So far, the strings I need to replace (and replace with) do not have any quotes (neither single nor double) in them. (It would be nice, though, to see a solution working well with strings containing quotes, of course.)  I know sed and awk / gawk can do such stuff principally, but can they also work with such dictionary files? Seems like gawk would be the right candidate for magiccommand, what are the right magicflags? How do I need to format my dictionary.txt?
56815
Is there a way to specify a regular expression to match every 2nd occurrence of a pattern in a string?  Examples   searching for a against string abcdabcd should find one occurrence at position 5 searching for ab  against string abcdabcd should find one occurrence at position 5 searching for dab  against string abcdabcd should find no occurrences searching for a against string aaaa should find two occurrences at positions 2 and 4
93119
I am trying to delete certain text that appears before / on every line.   I have something like:  testing.db.com/7fad416d-f2b3-4259-b98d-2449957a3123 testing.db.com/8a8589bf-49e3-4cd7-af15-6753067355c6   and I just want to end up with:   7fad416d-f2b3-4259-b98d-2449957a3123 8a8589bf-49e3-4cd7-af15-6753067355c6    Can anyone help me with a regular expression? Everything I have found is deleting after /, not before.
42364
I want to replace a '+' with ', ' to label an attribute looking like "ZT10+ZT20+ZT30" to get "ZT10, ZT20, ZT30" using   regexp_replace("zone_nr", '+', ', ')   but I get an Eval Error: Invalid regular expression '+': quantifier does not follow a repeatable item.
35188
I didn't get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?  Edit: I work in python. But would like to know in general about most popular languages/tools (java, perl, sed).
26992
I have this file:  sometext1{ string1 }  sometext2{ string2 string3 }  sometext3{ string4 string5 string6 }   I want to search this file for a specific string and print everything before this string up to the opening { and everything after this string up to the closing }. I tried to achieve this with sed but if I try to print everything in the range /{/,/string2/ for example sed prints this:  sometext1{ string1 }  sometext2{ string2 sometext3{ string4 string5 string6 }   If I search for the string "string2" I need the output to be:   sometext2{ string2 string3 }   Thanks.
39933
How can I get the start and end positions of all matches using the re module? For example given the pattern r'[a-z]' and the string 'a1b2c3d4' I'd want to get the positions where it finds each letter. Ideally, I'd like to get the text of the match back too.
76287
I'm looking for a field calculator Python statement to delete only the first two letters of string entries. For Ex:  !Name!.strip([0:2])   I know this syntax is incorrect.
32215
I haven't used regular expressions at all, so I'm having difficulty troubleshooting. I want the regex to match only when the contained string is all numbers; but with the two examples below it is matching a string that contains all numbers plus an equals sign like "1234=4321". I'm sure there's a way to change this behavior, but as I said, I've never really done much with regular expressions.  string compare = "1234=4321"; Regex regex = new Regex(@"[\d]");  if (regex.IsMatch(compare)) {      //true }  regex = new Regex("[0-9]");  if (regex.IsMatch(compare)) {      //true }   In case it matters, I'm using C# and .NET2.0.
19883
How do I get the substring " It's big \"problem  " using a regular expression?  s = ' function(){  return " It\'s big \"problem  ";  }';
42738
I have a huge file (more than 2&nbsp;GB) where data is like below.  12,324,32342,E:fsdsf,23432,34534,45345,324  13,3224,342,E:werwefsdsf,23432,34534,45345,324  121,3244,33442,E:,23432,34534,45345,324   Here I need to replace all the occurrences of 4th column wherever it is encountering E: with a blank space "", but wherever it finds a string after E:, that should remain as it is.  The expected output would be:  12,324,32342,E:fsdsf,23432,34534,45345,324  13,3224,342,E:werwefsdsf,23432,34534,45345,324  121,3244,33442,,23432,34534,45345,324
76384
I have a trigger where i am assigning ID to a cusotm field like below -   D.customfield__c = acc.Id;   The ID is coming as 00P28000000EwpjEA0  But i need only 00P28000000Ewpj 15 char. Is there is a way to use substring in apex trigger. I can't use formula field.
25014
How can I recursively replace a string in all folders and files' name with a different string? I am running Red Hat 6 and I can find them with:  find . -name \*string\*   I've managed to do it for strings within files:  find . -type f -exec sed -i 's/string1/string2/g' {} +   but how could I replace in a similar way all file names?
6643
I am doing something where I realised I wanted to count how many /s I could find in a string, and then it struck me, that there were several ways to do it, but couldn't decide on what the best (or easiest) was.  At the moment I'm going with something like:  string source = "/once/upon/a/time/"; int count = source.Length - source.Replace("/", "").Length;   But I don't like it at all, any takers?  I don't really want to dig out RegEx for this, do I?  I know my string is going to have the term I'm searching for, so you can assume that...  Of course for strings where length > 1,  string haystack = "/once/upon/a/time"; string needle = "/"; int needleCount = ( haystack.Length - haystack.Replace(needle,"").Length ) / needle.Length;
24166
It took me a while to word this best.  Problem 1:  Is there a way to find lines in a text file that have the same string at the beginning and the same strings at the end?   Beginning and end strings not necessarily equal to each other.  Text between the two strings is not consistant in number of characters or number of hyphens.  A hyphen is in between notable strings (which I added to my large text file).  For example:  File:    AAAAA-tjhut-ghyut-FILE1.txt   BBB-fhuj-dnbhg-frt76-FILE2.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   CCCC-fjuk-dryy-fhuj-FILE3.txt   Lines to detect:    AAAAA-tjhut-ghyut-FILE1.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   Problem 2:  Is there a way to remove all but one of the lines containing the duplicate strings at the beginning and end from above?  Before:    AAAAA-tjhut-ghyut-FILE1.txt   AAAAA-ghtujukr-hgute7gr-xhyutt-FILE1.txt   AAAAA-VGYT-4d7tt-xhyutt-FILE1.txt   After:    AAAAA-tjhut-ghyut-FILE1.txt   Big thanks for any advice.  Note: I think using the occurances of the first hyphen and last hyphen can be used to locate the duplicate strings.
3048
Say I have an enum which is just public enum Blah {     A, B, C, D }  and I would like to find the enum value of a string, for example &quot;A&quot; which would be Blah.A. How would it be possible to do this? Is the  the method I need? If so, how would I use this?