How to catch alternative into the nested group?  I want to return first capturing group of: (.*)((core\/)?\/misc\/drupal\.js) (i.e. anything before the string core/misc/drupal.js which may or might not contain core/).  However, the core/ part always gets included to the first capturing group and not the second as supposed.  See also  for an example.
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}?
40669
I want to reverse a regular expression. I.e. given a regular expression, I want to produce any string that will match that regex.  I know how to do this from a theoretical computer science background using a finite state machine, but I just want to know if someone has already written a library to do this. :)  I'm using Python, so I'd like a Python library.  To reiterate, I only want one string that will match the regex. Things like "." or ".*" would make an infinite amount of strings match the regex, but I don't care about all options.  I'm willing for this library to only work on a certain subset of regex.
15365
In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?  I usually just copy the string to a new variable then bind it to the s/// regex that does the replacement on the new string, but I was wondering if there is a better way to do this?  $newstring = $oldstring; $newstring =~ s/foo/bar/g;
108459
Are Python and JavaScript regular expression syntax identical?   If not, then:    What are the important differences between them Is there a python library that "implements" JavaScript regexps?
114561
Could I get an example as to how these three elements (are these called metacharacters?) differ?  I know that * means all or nothing, but I am not sure if it's the right way to think about it. On the other hand . and ? seem the same. They match one character, right?
8360
I would like to do the following: $find = &quot;start (.*) end&quot;; $replace = &quot;foo \1 bar&quot;;  $var = &quot;start middle end&quot;; $var =~ s/$find/$replace/;  I would expect $var to contain &quot;foo middle bar&quot;, but it does not work. Neither does: $replace = 'foo \1 bar';  Somehow I am missing something regarding the escaping.
34869
How can I iterate, loop, process, or otherwise do something, with each element from a comma separated list of things?  This question       , and the are already lots of very good answers everywhere. However I think it would also be valuable to have a single reference point where all such alternative techniques are explained in detail, with their advantages and disadvantages discussed.  All of plain-TeX, LaTeX, LaTeX3, LuaTeX, Context, etoolbox, pgffor, etc. answers are invited. Please consider explaining, for example:   How does the command/method deal with whitespace around items? How does the command/method deal with empty/missing items? (e.g. a,b,,c) How does the command/method deal with a trailing comma? Can the command/method work of a list stored on a macro? Is each iteration evaluated globally or on a local group? (i.e., if a command is defined during an iteration, does the command survive the loop?) Do items get expanded or somehow mangled before being processed? What about lists where items are key=value or some other kind of pairs? Does the method work for lists separated with something other than a comma? Any other thing I should know before deciding to use this method?
43887
What's the best/most efficient way to extract text set between parenthesis? Say I wanted to get the string "text" from the string "ignore everything except this (text)" in the most efficient manner possible.  So far, the best I've come up with is this:  $fullString = "ignore everything except this (text)"; $start = strpos('(', $fullString); $end = strlen($fullString) - strpos(')', $fullString);  $shortString = substr($fullString, $start, $end);   Is there a better way to do this? I know in general using regex tends to be less efficient, but unless I can reduce the number of function calls, perhaps this would be the best approach? Thoughts?
80375
I was wondering if there is any way to escape a CDATA end token (]]&gt;) within a CDATA section in an xml document. Or, more generally, if there is some escape sequence for using within a CDATA (but if it exists, I guess it'd probably only make sense to escape begin or end tokens, anyway).   Basically, can you have a begin or end token embedded in a CDATA and tell the parser not to interpret it but to treat it as just another character sequence.  Probably, you should just refactor your xml structure or your code if you find yourself trying to do that, but even though I've been working with xml on a daily basis for the last 3 years or so and I have never had this problem, I was wondering if it was possible. Just out of curiosity.  Edit:  Other than using html encoding...
62549
I'm having a bit of trouble getting a Python regex to work when matching against text that spans multiple lines. The example text is ('\n' is a newline)  some Varying TEXT\n \n DSJFKDAFJKDAFJDSAKFJADSFLKDLAFKDSAF\n [more of the above, ending with a newline]\n [yep, there is a variable number of lines here]\n \n (repeat the above a few hundred times).   I'd like to capture two things: the 'some_Varying_TEXT' part, and all of the lines of uppercase text that comes two lines below it in one capture (i can strip out the newline characters later).  I've tried with a few approaches:  re.compile(r"^&gt;(\w+)$$([.$]+)^$", re.MULTILINE) # try to capture both parts re.compile(r"(^[^&gt;][\w\s]+)$", re.MULTILINE|re.DOTALL) # just textlines   and a lot of variations hereof with no luck. The last one seems to match the lines of text one by one, which is not what I really want. I can catch the first part, no problem, but I can't seem to catch the 4-5 lines of uppercase text. I'd like match.group(1) to be some&#95;Varying&#95;Text and group(2) to be line1+line2+line3+etc until the empty line is encountered.  If anyone's curious, its supposed to be a sequence of aminoacids that make up a protein.
58910
I'm especially terrible with Regex, but reworked one I found online to suit my needs, but it keeps throwing the "no viable alternative at character '\'" error. This pattern works when tested in regex101.com, regexplanet.com, and rubular.com. I thought I had escaped everything that needed escaping. Right, now  I'm out of my depth with this. Hopefully someone here can give me some insight.  In case anyone needs to know, the regex needs to find the first email address in an the email body (which is from a submitted form) that immediately follows the word "From:" (at this point I'm unsure if there will be a space after "From:" or not), since there could be multiple email addresses in the text.  Thanks in advance to anyone who can help!  Here's my code:  if (email.Subject.Contains('xxxx') || email.fromAddress == 'xxxx'){         Pattern myPattern = Pattern.compile('From:(\\s(?:[a-z0-9!#$%&amp;'*+\\/=?^_'{|}~-]+(?:\\.[a-z0-9!#$%&amp;'*+\\/=?^_'{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\]))');         Matcher myMatcher = myPattern.matcher(email.plainTextBody);         Set&lt;String&gt; emails = new Set&lt;String&gt;();         while(myMatcher.find()) {             emails.add(matcher.group(1));         }     }
13479
Note that this function does not have a "{" and "}" body.  Just a try/catch block:  void func( void ) try {     ... } catch(...) {     ... }   Is this intentionally part of C++, or is this a g++ extension?  Is there any purpose to this other than bypass 1 level of {}?  I'd never heard of this until I ran into
55644
I'm looking for Python code that removes C and C++ comments from a string. (Assume the string contains an entire C source file.)  I realize that I could .match() substrings with a Regex, but that doesn't solve nesting /*, or having a // inside a /* */.  Ideally, I would prefer a non-naive implementation that properly handles awkward cases.
33592
I have a group of strings in Javascript and I need to write a function that detects if another specific string belongs to this group or not.  What is the fastest way to achieve this? Is it alright to put the group of values into an array, and then write a function that searches through the array?  I think if I keep the values sorted and do a binary search, it should work fast enough. Or is there some other smart way of doing this, which can work faster?
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.
36235
I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector.  I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is?  EDIT: The attribute filters allow you to select based on patterns of an attribute value.
3909
Is there a way to achieve the equivalent of a  in javascript regular expressions?  I need to match a string that does not start with a specific set of characters.  It seems I am unable to find a regex that does this without failing if the matched part is found at the beginning of the string.  Negative lookbehinds seem to be the only answer, but javascript doesn't have one.  EDIT: This is the regex that I would like to work, but it doesn't:  (?&lt;!([abcdefg]))m  So it would match the 'm' in 'jim' or 'm', but not 'jam'