I am replacing string content as:  re.sub(all, val, parsedData['outData'])   where all contains some round braces and might contain other characters.  &gt;&gt;&gt; print all PICDSPVERS="DspFw:1.0008(1.0008),Fpga1:2.0925(2.0925),Fpga2:1.0404(1.0404),Mcu:1.0000(1.0000)"  Because of which matching fails. The pattern is coming from some interface, so I don't want to put \\ in the data.  I tried with 'r' and re.U option also, but still the match fails.  re.search('PICDSPVERS="DspFw:1.0008(1.0008)', parsedData['outData'])   How can we direct Python to treat a matching pattern as a string?  I am using Python 2.x.
22511
I want to use input from a user as a regex pattern for a search over some text.  It works, but how I can handle cases where user puts characters that have meaning in regex? For example, the user wants to search for Word (s): regex engine will take the (s) as a group.  I want it to treat it like a string &quot;(s)&quot; .  I can run replace on user input and replace the ( with \( and the ) with \) but the problem is I will need to do replace for every possible regex symbol. Do you know some better way ?
46901
In Python, I can compile a regular expression to be case-insensitive using re.compile:  &gt;&gt;&gt; s = 'TeSt' &gt;&gt;&gt; casesensitive = re.compile('test') &gt;&gt;&gt; ignorecase = re.compile('test', re.IGNORECASE) &gt;&gt;&gt;  &gt;&gt;&gt; print casesensitive.match(s) None &gt;&gt;&gt; print ignorecase.match(s) &lt;_sre.SRE_Match object at 0x02F0B608&gt;   Is there a way to do the same, but without using re.compile. I can't find anything like Perl's i suffix (e.g. m/test/i) in the documentation.
111242
I have a , and I'm trying to match it to a regular expression to pull out some groups. The problem I'm having is that the URL can either end or continue with a "/" and more URL text. I'd like to match URLs like this:        But not match something like this:      So, I thought my best bet was something like this:    /(.+)/(\d{4}-\d{2}-\d{2})-(\d+)[/$]   where the character class at the end contained either the "/" or the end-of-line. The character class doesn't seem to be happy with the "$" in there though. How can I best discriminate between these URLs while still pulling back the correct groups?
94801
I have the following C# which simply replaces parts of the input string that look like EQUIP:19d005 into URLs, like this:  input = Regex.Replace(input, @"(EQUIP:)(\S+)", @"&lt;a title=""View equipment item $2"" href=""/EquipmentDisplay.asp?eqnum=$2""&gt;$1$2&lt;/a&gt;", RegexOptions.IgnoreCase);   The HTML ends up looking like this.  &lt;a title="View equipment item 19d005" href="/EquipmentDisplay.asp?eqnum=19d005"&gt;EQUIP:19d005&lt;/a&gt;   The only trouble is that the destination page expects the eqnum querystring to be all UPPERCASE so it returns the correct equipment when eqnum=19D005 but fails if it receives eqnum=19d005.  I guess I can modify and correct EquipmentDisplay.asp's errant requirement of uppercase values however, if possible I'd like to make the C# code comply with the existing classic ASP page by uppercasing the $2 in the Regex.Replace statement above.  Ideally, I'd like the HTML returned to look like this:  &lt;a title="View equipment item 19d005" href="/EquipmentDisplay.asp?eqnum=19D005"&gt;EQUIP:19d005&lt;/a&gt;   Notice although the original string was EQUIP:19d005 (lowercase), only the eqnum= value is uppercased.  Can it be done and if so, what's the tidiest way to do it?
120264
I got this packet captured with tcpdump but I'm not sure how to use the --hex-string param to match the packet. Can someone show me how to do it?  11:18:26.614537 IP (tos 0x0, ttl 17, id 19245, offset 0, flags [DF], proto UDP (17), length 37)     x.x.187.207.1234 &gt; x.x.152.202.6543: [no cksum] UDP, length 9         0x0000:  f46d 0425 b202 000a b853 22cc 0800 4500  .m.%.....S"...E.         0x0010:  0025 4b2d 4000 1111 0442 5ebe bbcf 6701  .%K-@....B^...g.         0x0020:  98ca 697d 6989 0011 0000 ffff ffff 5630  ..i}i.........V0         0x0030:  3230 3300 0000 0000 0000 0000            203.........
18973
I need to write a function that receives a string and a regex. I need to check if there is a match and return the start and end location of a match. (The regex was already compiled by qr//.)  The function might also receive a "global" flag and then I need to return the (start,end) pairs of all the matches.  I cannot change the regex, not even add () around it as the user might use () and \1. Maybe I can use (?:).  Example: given "ababab" and the regex qr/ab/, in the global case I need to get back 3 pairs of (start, end).
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).
33382
Can a regular expression match whitespace or the start of a string?  I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.  &gt;&gt;&gt; import re &gt;&gt;&gt; text = u'GBP 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches GBP with any prefix u'\xa3 5 Off when you spend \xa375.00'  &gt;&gt;&gt; re.sub(ur'^GBP([\W\d])', ur'£\g&lt;1&gt;', text) # matches at start only u'\xa3 5 Off when you spend GBP75.00'  &gt;&gt;&gt; re.sub(ur'(\W)GBP([\W\d])', ur'\g&lt;1&gt;£\g&lt;2&gt;', text) # matches whitespace prefix only u'GBP 5 Off when you spend \xa375.00'   Can I do both of the latter examples at the same time?
3017
I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on a different unix variant), it stops matching. Why?
32741
The  states that:     Since 1.0.4, case insensitive regular expressions can be used by prefixing the pattern with ~*.   And gives the example:  map $uri $myvalue {     /aa                   /mapped_aa;     ~^/aa/(?&lt;suffix&gt;.*)$  $suffix; }   I updated to nginx/1.2.7 to make use of this, and naive regexes work okay, but variables don't. When I try the above syntax I get the error:  nginx: [emerg] pcre_compile() failed: unrecognized character after (?&lt; in "^/aa/(?&lt;suffix&gt;.*)$" at "suffix&gt;.*)$"   I also tried the following syntaxes, but none of them worked:  ~^(.*)$  $1; ~^(.*)$  \1;   but neither of them worked either.  Does anyone know how to get variables to work in regular expressions in HttpMapModule?
10266
I have embedded a Python interpreter in a C program.  Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8).  How do I decode the contents of this char array into a Python string?  The Python string should in general be of type unicode—for instance, a 0x93 in Windows-1252 encoded input becomes a u'\u0201c'.  I have attempted to use PyString_Decode, but it always fails when there are non-ASCII characters in the string.  Here is an example that fails:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *py_string;       Py_Initialize();       py_string = PyString_Decode(c_string, 1, "windows_1252", "replace");      if (!py_string) {           PyErr_Print();           return 1;      }      return 0; }   The error message is UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 0: ordinal not in range(128), which indicates that the ascii encoding is used even though we specify windows_1252 in the call to PyString_Decode.  The following code works around the problem by using PyString_FromString to create a Python string of the undecoded bytes, then calling its decode method:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *raw, *decoded;       Py_Initialize();       raw = PyString_FromString(c_string);      printf("Undecoded: ");      PyObject_Print(raw, stdout, 0);      printf("\n");      decoded = PyObject_CallMethod(raw, "decode", "s", "windows_1252");      Py_DECREF(raw);      printf("Decoded: ");      PyObject_Print(decoded, stdout, 0);      printf("\n");      return 0; }
37476
What is the easiest way to match non-ASCII characters in a regex? I would like to match all words individually in an input string, but the language may not be English, so I will need to match things like ü, ö, ß, and ñ. Also, this is in Javascript/jQuery, so any solution will need to apply to that.
7509
I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the [link content][link id] syntax. I use the following code:  data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   It works well, but now I want to do this with a RegExp object. So I set up the following bit of code:  var r = new RegExp( '\[(.*?)\][ ]*\[([0-9]+)\]', 'g' ); data = data.replace( r, '&lt;a href="$2"&gt;$1&lt;/a&gt;' );   But it doesn't work. It even says that my regular expression (which works since the first example does a good job) is invalid:     unmatched ) in regular expression   I think it must have to do with some RegExp-object peculiarities I am not aware of. What am I doing wrong and how can the problem be solved?
64797
Situation: It started out as me  for the literal string C-c in  but it ended up omitting the - sign and showing results which contained the strings C/C++ and C &amp; C++.  is an example of a post which contains that string of characters (yet fails to show up in the results).  Things I've tried:   post suggests that I can use the undocumented code: operator, but when I do that, it just wraps the whole term in double quotes like .  As @terdon in Unix &amp; Linux chat has , using this  does yield some relevant results, but it doesn't show me  that is supposed to be there. edit: It appears that the Symbolhound query no longer returns that result.  Finally,  says that you can search for literal characters, but as you can see:    Quoted phrases are exact matches except for case-sensitivity, for example, you can search  or .  The second example (symbols) leads to 0 results.  So by now I assume that the search engine has changed (but the old documentation still lingers on this site). Is there a method for me to search for strings that include special (or is it literal?) characters?
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?
77611
Good day. Using only Linux OS tools, how would you convert the following text from this: cat latest.csv apsga,alp1acscf0001vm001oam001p1n004v001,192.7.129.7,UVP apsga,alp1acscf0001vm001oam001p1n004v002,192.7.129.8,UVP apsga,alp1acscf0001vm002oam001p1n004v001,192.7.129.9,UVP apsga,alp1acscf0001vm003oam001p1n004v001,192.7.129.10,UVP apsga,alp1acscf0001vm004cif001p1n004v001,192.7.129.11,UVP apsga,alp1acscf0001vm004cif001p1n004v002,192.7.129.12,UVP apsga,alp1acscf0001vm005cif001p1n004v001,192.7.129.13,UVP  I managed to get the following result: cat latest.csv`|awk -F',' '{print $2, $3}'|awk '{ $1 = substr($1,1,21); print $1&quot;,&quot;$2}' alp1acscf0001vm001oam,192.7.129.7 alp1acscf0001vm001oam,192.7.129.8 alp1acscf0001vm002oam,192.7.129.9 alp1acscf0001vm003oam,192.7.129.10 alp1acscf0001vm004cif,192.7.129.11 alp1acscf0001vm004cif,192.7.129.12 alp1acscf0001vm005cif,192.7.129.13  I would like the end result to look like this: ALP1A/alp1acscf0001v,UUID,192.7.129.7,SSH2,alp1acscf0001vm001oam ALP1A/alp1acscf0001v,UUID,192.7.129.8,SSH2,alp1acscf0001vm001oam ALP1A/alp1acscf0001v,UUID,192.7.129.9,SSH2,alp1acscf0001vm002oam ALP1A/alp1acscf0001v,UUID,192.7.129.10,SSH2,alp1acscf0001vm003oam ALP1A/alp1acscf0001v,UUID,192.7.129.11,SSH2,alp1acscf0001vm004cif ALP1A/alp1acscf0001v,UUID,192.7.129.12,SSH2,alp1acscf0001vm004cif ALP1A/alp1acscf0001v,UUID,192.7.129.13,SSH2,alp1acscf0001vm005cif  Thanks in advance, Bjoern
87368
I did tried sed and awk, but its not working as the character involves / which is already there in command as delimiter. Please let me know how can I achieve this. Below is a sample Example. We want to remove the commented sections, i.e /*.....*/ /*This is to print the output data*/ proc print data=sashelp.cars; run; /*Creating dataset*/ data abc; set xyz; run;