I am trying to match the contents between BEGIN and END into a capture group called numbers from this string note:     string note = @"BEGIN    781-222-3311    9789001122    7817770000 to 7817770010    END";   The variable I am putting the matched group value into is numbers. What I am using to match the string is the following:     string numbers = "";    Regex numberEncapsulationRegex = new Regex(@"begin\n(?&lt;numbers&gt;.+)\nend", RegexOptions.IgnoreCase);    Match numberCatch = numberEncapsulationRegex.Match(note);    if (numberCatch.Success)    {        Console.WriteLine("SUCCESS: \n");        numbers += numberCatch.Groups["numbers"].Value;    }   I have tried using RegexOptions.Multiline along with RegexOptions.IgnoreCase, and have also tried using:     (?i:begin)\n(?&lt;numbers\&gt;.+)\n(?i:end)    (?i:begin)(\n?&lt;numbers&gt;.+\n)(?i:end)    (?&lt;=BEGIN)(.*)(?=END)   Cannot get this to work. Thank you for reading and for helping, if willing.
4355
For example, this regex  (.*)&lt;FooBar&gt;   will match:  abcde&lt;FooBar&gt;   But how do I get it to match across multiple lines?  abcde fghij&lt;FooBar&gt;
59657
Regex.IsMatch( "foo", "[\U00010000-\U0010FFFF]" )    Throws: System.ArgumentException: parsing "[-]" - [x-y] range in reverse order.  Looking at the hex values for \U00010000 and \U0010FFF I get: 0xd800 0xdc00 for the  first character and 0xdbff 0xdfff for the second.  So I guess I have really have one problem. Why are the Unicode characters formed with \U split into two chars in the string?
1430
I want to check whether Value1 below contains "abc" within the first X characters. How would you check this with an if statement?  var Value1 = "ddabcgghh";  if (Value1.Contains("abc")) {     found = true; }   It could be within the first 3, 4 or 5 characters.
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
101666
I want to split BillingStreet into a custom Street__c and HouseNumber__c. According to what I have read so far online, I need to:   Instantiate a new Pattern object  //Pattern 'Test Street 123' OR '123 Test Street' OR 'Test 123 Street'  Pattern MyPattern = Pattern.compile('[^\\d]*([\\d]+)[^\\d]*');  Instantiate a new Matcher object  Matcher MyMatcher = MyPattern.matcher(account.BillingStreet);  Process the result  if(MyMatcher.matches()){     account.Street__c = MyMatcher.group(???);     account.HouseNumber__c = MyMatcher.group(1);   }    The code for the House Number is working. But I need it to work for Street and also to enhance the Regex with the following examples: 'Further Test Street 123', '123 Further Test Street', 'Test Street 123a', '123a Test Street', 'Test 123a Street', 'Further Test Street 123a', '123a Further Test Street', 'Street 123', '123 Street', 'Street 123a', '123a Street' and all the same with 'Further-Test-Street 123' ...
86651
ab&amp;2e;1652769179"/>   i did correlction using rerular expression ab&amp;2e;(.*?)"/>  but during execution some times extra text (cd&amp;3d;) adding to the data like  ab&amp;2e;cd&amp;3d;1652769179"/>  So need to ignore data "cd&amp;3d;"  Please let me know any idea to ignore text cd&amp;3d; and capture 1652769179 only using expresiion ab&amp;2e;(.*?)"/>  Thanks Raghav
51943
Is it possible to skip a couple of characters in a capture group in regular expressions? I am using .NET regexes but that shouldn't matter.  Basically, what I am looking for is:     [random text]AB-123[random text]   and I need to capture 'AB123', without the hyphen.  I know that AB is 2 or 3 uppercase characters and 123 is 2 or 3 digits, but that's not the hard part. The hard part (at least for me) is skipping the hyphen.  I guess I could capture both separately and then concatenate them in code, but I wish I had a more elegant, regex-only solution.  Any suggestions?
16529
I want to determine whether a multi-line string ends with a line containing specified pattern.  These code failed, it doesn't match.  s=`echo hello &amp;&amp; echo world &amp;&amp; echo OK` [[ "$s" =~ 'OK$' ]] &amp;&amp; echo match
92309
I have a string:   allPunctuation = '~!@#$%^*()_+|}{":?&gt;&lt;`=;/.,][-\'\\';   This string contains APEX's way of escaping characters so I can include the ' and the \ characters.   When I pass this string into the replaceAll() method I get back an error because the escape characters are not carried over and the regex needs the escape characters. Is there a way around this?  ie: when I system.debug allPunctuation I get back: ~!@#$%^*()_+&#124;}{":?>&lt;`=;/.,][-'\ This clearly doesn't have the escape characters anymore.   My second thought was to utilize the matcher method. Documentation found here:    I am not sure why, but it is returning back a false. To me it seems like it shouldn't be affected by the escape quotes. And legalName has all sorts of punctuation in it.   Pattern NonAlphanumeric = Pattern.compile('[^a-zA-Z0-9 ]'); Matcher matcher = NonAlphanumeric.matcher(legalName); //system.debug(matcher) ---&gt; false   Could someone point me in the right direction?
7245
I would like to build a regexp in Java that would be passed in a FilenameFilter to filter the files in a dir.  The problem is that I can't get the hang of the regexp "mind model" :)  This is the regexp that I came up with to select the files that I would like to exclude   ((ABC|XYZ))+\w*Test.xml  What I would like to do is to select all the files that end with Test.xml but do not start with ABC or XYZ.  Could you please add any resources that could help me in my battle with regexps.  Thanks  The following resource explains a lot of things about regexp
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}?
919
Unfortunately, despite having tried to learn regex at least one time a year for as many years as I can remember, I always forget as I use them so infrequently. This year my new year's resolution is to not try and learn regex again - So this year to save me from tears I'll give it to Stack Overflow. (Last Christmas remix).  I want to pass in a string in this format {getThis}, and be returned the string getThis. Could anyone be of assistance in helping to stick to my new year's resolution?    Related questions on Stack Overflow:
119008
Given this string:  SET @text = "&lt;a href=""https://salesforce.stackexchange.com""target=""_blank""&gt;Salesforce&lt;/a&gt; &lt;a href=""https://stackoverflow.com"" target=""_blank""&gt;Everything else&lt;/a&gt;"   And this function:  SET @matching = '\s+(?:[^&gt;]*?\s+)?href="([^"]*)"' SET @output = RegExMatch(@text, @matching, 1)   How can I manage to find and print an arbitrary number of matches in my string? E.g. in above example, I would like to present e.g. a rowset with each URL in each row.
7153
Thinking about , i decided I can't even create a regular expression that will match roman numerals (let alone a context-free grammar that will generate them)  The problem is matching only valid roman numerals.  Eg, 990 is NOT "XM", it's "CMXC"  My problem in making the regex for this is that in order to allow or not allow certain characters, I need to look back. Let's take thousands and hundreds, for example.  I can allow M{0,2}C?M (to allow for 900, 1000, 1900, 2000, 2900 and 3000). However, If the match is on CM, I can't allow following characters to be C or D (because I'm already at 900).  How can I express this in a regex? If it's simply not expressible in a regex, is it expressible in a context-free grammar?
12575
It seems the .NET Regex.Replace method automatically replaces all matching occurrences.  I could provide a MatchEvaluator delegate that returns the matched string after the first replacement, rendering no change, but that sounds very inefficient to me.  What is the most efficient way to stop after the first replacement?
453
I need to write a Java Comparator class that compares Strings, however with one twist.  If the two strings it is comparing are the same at the beginning and end of the string are the same, and the middle part that differs is an integer, then compare based on the numeric values of those integers.  For example, I want the following strings to end up in order they're shown:   aaa bbb 3 ccc bbb 12 ccc ccc 11 ddd eee 3 ddd jpeg2000 eee eee 12 ddd jpeg2000 eee   As you can see, there might be other integers in the string, so I can't just use regular expressions to break out any integer.  I'm thinking of just walking the strings from the beginning until I find a bit that doesn't match, then walking in from the end until I find a bit that doesn't match, and then comparing the bit in the middle to the regular expression "[0-9]+", and if it compares, then doing a numeric comparison, otherwise doing a lexical comparison.  Is there a better way?  Update I don't think I can guarantee that the other numbers in the string, the ones that may match, don't have spaces around them, or that the ones that differ do have spaces.
54866
I want to grab the value of a hidden input field in HTML.  &lt;input type="hidden" name="fooId" value="12-3456789-1111111111" /&gt;   I want to write a regular expression in Python that will return the value of fooId, given that I know the line in the HTML follows the format  &lt;input type="hidden" name="fooId" value="**[id is here]**" /&gt;   Can someone provide an example in Python to parse the HTML for the value?