I wanted to extract what ever is within the below tokens   ${FNAME} ${LNAME} ${123}      FNAME LNAME 123.     I tried the below.  public static void main(String[] args) {      String input = "{FNAME} ${LNAME} ${123}";      Pattern p = Pattern.compile("\\$\\{");     Matcher m = p.matcher(input);       while (m.find()) {         System.out.println("Found a " + m.group() + ".");      }  }   Ended up wrongly. Beginner to reg expressions.
8109
I want to match a portion of a string using a  and then access that parenthesized substring:  var myString = "something format_abc"; // I want "abc"  var arr = /(?:^|\s)format_(.*?)(?:\s|$)/.exec(myString);  console.log(arr);     // Prints: [" format_abc", "abc"] .. so far so good. console.log(arr[1]);  // Prints: undefined  (???) console.log(arr[0]);  // Prints: format_undefined (!!!)   What am I doing wrong?    I've discovered that there was nothing wrong with the regular expression code above: the actual string which I was testing against was this:  "date format_%A"   Reporting that "%A" is undefined seems a very strange behaviour, but it is not directly related to this question, so I've opened a new one, .    The issue was that console.log takes its parameters like a printf statement, and since the string I was logging ("%A") had a special value, it was trying to find the value of the next parameter.
70279
I have the following in a file Output.dat. I need to extract the value between dn: uid= and ,ou=  dn: uid=user1,ou=Active,ou=Member,dc=domain,dc=org  dn: uid=user2@abc.com,ou=Active,ou=Member,dc=domain,dc=org  dn: uid=usertest,ou=Active,ou=Member,dc=domain,dc=org  dn: uid=abc1,ou=Active,ou=Member,dc=domain,dc=org   I tried using sed -e '/dn: uid=/,/,ou=/p' output.dat but  it returns complete line instead of value. When tried to use sed -e '/dn: uid=/,/,ou=/\1/p' output.dat  then got the following error: sed: -e expression #1, char 18: unknown command: `\'
18468
I'm developing an algorithm to parse a number out of a series of short-ish strings. These strings are somewhat regular, but there's a few different general forms and several exceptions. I'm trying to build a set of regexes that will handle the various forms and exceptions; I'll apply them one after another to see if I get a match.   One of these forms goes something like this:  X (Y) Z   Where:   X is a number I want to capture.  Z is static, pre-defined text. it's basically how I determine whether this particular form is applicable or not. Y is a a string of unknown length and content, surrounded by parenthesis.    Also: Y is optional; it doesn't always appear in a string with Z and X. So, I want to be able to extract the numbers from all of these strings:   10 Z 20 (foo) Z 30 (bar) Z   Right now, I have a regex that will capture the first one:  ([0-9]+) +Z   My problem is that I don't know how to construct a regex that will match a series of characters if and only if they're enclosed in parenthesis. Can this be done in a single regex?
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.
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
3542
I have a value like this:  "Foo Bar" "Another Value" something else   What regex will return the values enclosed in the quotation marks (e.g. Foo Bar and Another Value)?
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?
70098
I'm trying to get a regex that will match:  somefile_1.txt somefile_2.txt somefile_{anything}.txt   but not match:  somefile_16.txt   I tried  somefile_[^(16)].txt   with no luck (it includes even the "16" record)
18905
I've got a text file full of records where each field in each record is a fixed width.  My first approach would be to parse each record simply using string.Substring().  Is there a better way?   For example, the format could be described as:  &lt;Field1(8)&gt;&lt;Field2(16)&gt;&lt;Field3(12)&gt;   And an example file with two records could look like:  SomeData0000000000123456SomeMoreData Data2   0000000000555555MoreData       I just want to make sure I'm not overlooking a more elegant way than Substring().    Update:  I ultimately went with a regex like Killersponge suggested:  private readonly Regex reLot = new Regex(REGEX_LOT, RegexOptions.Compiled); const string REGEX_LOT = "^(?&lt;Field1&gt;.{6})" +                         "(?&lt;Field2&gt;.{16})" +                         "(?&lt;Field3&gt;.{12})";   I then use the following to access the fields:  Match match = reLot.Match(record); string field1 = match.Groups["Field1"].Value;
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).
108524
I need a RegEx pattern for extracting all the properties of an image tag.  As we all know, there are lots of malformed HTML out there, so the pattern has to cover those possibilities.  I was looking at this solution  but it didn't quite get it all:  I come up something like:  (alt|title|src|height|width)\s*=\s*["'][\W\w]+?["']   Is there any possibilities I'll be missing or a more efficient simple pattern?  EDIT: Sorry, I will be more specific, I'm doing this using .NET so it's on the server side. I've already a list of img tags, now I just need to parse the properties.
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?
111292
I'm trying to write a regex function that will identify and replace a single instance of a match within a string without affecting the other instances.  For example, I have this string:  12||34||56   I want to replace the second set of pipes with ampersands to get this string:  12||34&amp;&amp;56   The regex function needs to be able to handle x amount of pipes and allow me to replace the nth set of pipes, so I could use the same function to make these replacements:  23||45||45||56||67 -&gt; 23&amp;&amp;45||45||56||67  23||34||98||87 -&gt; 23||34||98&amp;&amp;87   I know that I could just split/replace/concat the string at the pipes, and I also know that I can match on /\|\|/ and iterate through the resulting array, but I'm interested to know if it's possible to write a single expression that can do this.  Note that this would be for Javascript, so it's possible to generate a regex at runtime using eval(), but it's not possible to use any Perl-specific regex instructions.
25827
I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep:  find . -iname '*.py' | xargs grep -e 'YOUR_PATTERN'   But if I need to find patterns that spans on more than one line, I'm stuck because vanilla grep can't find multiline patterns.
55851
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within quotes.  user@host:~/Desktop$ grep -E '\&lt;H' test Hello World user@host:~/Desktop$ grep -E \&lt;H test   [test contains the string Hello World]  But matching end and beginning of file works without dollar:  user@host:~/Desktop$ egrep d$ test Hello World   Why is it so? And what is the rule?
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.
118546
Is there a regular expression that matches valid regular expressions?   (I know there are several flavors of regexps. One would do.)