For example, I have a target string like: str='Every "red","white","blue" flower is $7.'  If I run /Every ("(.+)",?)+ flower is \$(.+)/.exec(str), I will get "red","white","blue" as a whole output element, but what I want is ["red,"white","blue"].  Is there a way to do this, or I can only use split?   Thanks!
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}?
35787
Say I have this file:  hello world hello world   This program  #!/bin/bash  for i in $(cat $1); do     echo "tester: $i" done   outputs  tester: hello tester: world tester: hello tester: world   I'd like to have the for iterate over each line individually ignoring whitespaces though, i.e. the last two lines should be replaced by  tester: hello world   Using quotes for i in "$(cat $1)"; results in i being assigned the whole file at once. What should I change?
1707
I have several strings in the rough form:  [some text] [some number] [some more text]   I want to extract the text in [some number] using the Java Regex classes.  I know roughly what regular expression I want to use (though all suggestions are welcome). What I'm really interested in are the Java calls to take the regex string and use it on the source data to produce the value of [some number].  EDIT: I should add that I'm only interested in a single [some number] (basically, the first instance). The source strings are short and I'm not going to be looking for multiple occurrences of [some number].
113626
I am looking for a way to extract a variable length substring from a string.  My cells will look something like:  ABC - DEF ABCDE - DEF ABCD - ABC   I want to split the string at the - character, so the cells will become:  ABC ABCDE ABCD   This should be done with a formula and not VBScript.  I am using Excel 2010  EDIT  I found that the dataset doesn't always contain the - character, meaning there should be no change.
92395
I want to split a command line like string in single string parameters. How look the regular expression for it. The problem are that the parameters can be quoted. For example like:  "param 1" param2 "param 3"  should result in:  param 1, param2, param 3
2094
I'm trying to iterate over the words of a string.  The string can be assumed to be composed of words separated by whitespace.  Note that I'm not interested in C string functions or that kind of character manipulation/access. Also, please give precedence to elegance over efficiency in your answer.  The best solution I have right now is:  #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt;  using namespace std;  int main() {     string s = "Somewhere down the road";     istringstream iss(s);      do     {         string subs;         iss &gt;&gt; subs;         cout &lt;&lt; "Substring: " &lt;&lt; subs &lt;&lt; endl;     } while (iss); }   Is there a more elegant way to do this?
38993
I am new to UNIX and am trying to learn basic level text processing in UNIX so maybe this question may seem very basic but I would really appreciate any guidance.  I have a text file as below  A 1 B 2 C 9 D 1 A 5 B 3 C 4 A 6 C 7 A 5 C 1   for which I was able to piece together a command with some help as below  cat | awk 'BEGIN{OFS=FS=" "}!(($1,$2)in c){c[$1,$2]=1;r[$1]=r[$1] OFS $2} END{for(i in r){print i r[i]}}'   inside a shell script to get it to the format below:  A 1 5 6 5 B 2 3 C 9 4 7 1 D 1   My shell script will also take an argument k  (=7 say)  In this case, my script should sample 1 element from each box (A,B,C,D) until it has a total of 7 elements sampled. This will be like follows: First pick 1 from A, then 2 from B, 9 from C, 1 from D, 5 from A, 3 from B, 4 from C and display  A 1 5 B 2 3 C 9 4 D 1   If instead I had k = 9 as my input, then my output should be  A 1 5 6 B 2 3 C 9 4 7 D 1
2047
I have a string which is like this:  this is "a test"   I'm trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I'm looking for is:  ['this','is','a test']   PS. I know you are going to ask "what happens if there are quotes within the quotes, well, in my application, that will never happen.
108624
I have a string in the next format  id;some text here with possible ; inside   and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; inside  I know how to split the string (for instance, with cut -d ';' -f1), but it will split to more parts since I have ; inside the left part.
39746
I have a java string, which has a variable length.   I need to put the piece "&lt;br&gt;" into the string, say each 10 characters.   For example this is my string:  `this is my string which I need to modify...I love stackoverlow:)`   How can I obtain this string?:  `this is my&lt;br&gt; string wh&lt;br&gt;ich I nee&lt;br&gt;d to modif&lt;br&gt;y...I love&lt;br&gt; stackover&lt;br&gt;flow:)`   Thanks
33653
I have a text in a text file, where I want everything that is between strings like \{{[} and {]}\} to be deleted - including these strings themselves.  These two string can lie on different lines as well as on the same line. In either case,  on the line on which the beginning \{{[} lies, I don't want the text before, i.e. left, of it to be deleted - and the same holds for the text after {]}\}.  Here is an example: Given a text file with the content   Bla Bla bla bla \{{[} more bla bla even more bla bla bla bla.   A lot of stuff might be here.  Bla bla {]}\} finally done.  Nonetheless, the \{{[} show {]}\} goes on.   the script should return another text file with the content  Bla Bla bla bla  finally done.  Nonetheless, the  goes on.   Unfortunately this simple-looking task turned out to be too difficult for me to do with sed. I'm happy with any solution in any language, as long as I don't have to install anything on my standard linux machine (C and some java is already installed).
82721
$ a='"apple","ball","cat"' $ a='['$a $ echo $a ["apple","ball","cat" $ a=$a']' $ echo $a b   I'm stumped hard by the result b while I expect to see ["apple,"ball","cat"]. What am I missing here?  This is from bash shell on Mac. Also see it on CentOS 7, while not on Fedora. Can someone please explain?
12603
I am using the function below to match URLs inside a given text and replace them for HTML links. The regular expression is working great, but currently I am only replacing the first match.  How I can replace all the URL? I guess I should be using the exec command, but I did not really figure how to do it.  function replaceURLWithHTMLLinks(text) {     var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&amp;@#\/%?=~_|!:,.;]*[-A-Z0-9+&amp;@#\/%=~_|])/i;     return text.replace(exp,"&lt;a href='$1'&gt;$1&lt;/a&gt;");  }
112657
I know I can solve this problem several ways, but I'm wondering if there is a way to do it using only bash built-ins, and if not, what is the most efficient way to do it.  I have a file with contents like  AAA B C DDD FOO BAR   by which I only mean it has several lines and each line may or may not have spaces.  I want to run a command like  cmd AAA "B C DDD" "FOO BAR"   If I use cmd $(&lt; file) I get  cmd AAA B C DDD FOO BAR   and if I use cmd "$(&lt; file)" I get  cmd "AAA B C DDD FOO BAR"   How do I get each line treated a exactly one parameter?
112773
I need to be able to take a string like:  '''foo, bar, "one, two", three four'''   into:  ['foo', 'bar', 'one, two', 'three four']   I have an feeling (with hints from #python) that the solution is going to involve the shlex module.
81981
In python   re.sub(r"(?&lt;=.)(?=(?:...)+$)", ",", stroke )    To split a number by triplets, e.g.:   echo 123456789 | python -c 'import sys;import re; print re.sub(r"(?&lt;=.)(?=(?:...)+$)", ",",  sys.stdin.read());'  123,456,789   How to do the same with bash/awk?
65652
In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers.  For example, I can write a bash shell script that prints the integers between 1 and 10: #!/bin/bash  for i in {1..10} do  echo $i done  Is it possible to instead iterate over a loop control variable that is a string, if I provide a list of strings?  For example, suppose that I have a string fname that represents a file name.  I want to call a set of commands for each file name.  For example, I might want to print the contents of fname using a command like this: #!/bin/bash  for fname in {&quot;a.txt&quot;, &quot;b.txt&quot;, &quot;c.txt&quot;} do  echo $fname done  In other words, on the first iteration, fname should have the value fname=&quot;a.txt&quot;, while on the second iteration, fname should have the value fname=&quot;b.txt&quot;, and so on.  Unfortunately, it seems that the above syntax is not quite correct.  I would like to obtain the output:  a.txt b.txt c.txt  but when I try the above code, I obtain this output:  {a.txt, b.txt, c.txt}  Can you please help me determine the correct syntax, so that I can iteratively change the value/contents of the variable fname?  Thank you for your time.