regex

Ruby isPrime Method

('1' * N) !~ /^1?$|^(11+?)\1+$/ On the net, I found this piece of Ruby code that works for N >= 0 that determines whether or not N is a prime. From what I can tell, it looks like play with regex but I have no idea how it works. Could someone tell me how it works? ...

Regexp matching of list of quotes strings - unquoted

in Javascript, the following: var test = '"the quick" "brown fox" "jumps over" "the lazy dog"'; var result = test.match(/".*?"/g); alert(result); yields "the quick","brown fox","jumps over","the lazy dog" I want each matched element to be unquoted: the quick,brown fox,jumps over,the lazy dog what regexp will do this? ...

How to Regex search/replace only first occurrance in a string in .NET?

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? ...

Regular expression to filter files in OpenFileDialog

Hi, I would like to know how to filter files in a open file dialog (in winforms) based on a regular expression. Files have all same extensions (.xml). Big files are split up into several files with the same name only to be separated with _1 ... We only want to show the files without _1 (first data file) the open file dialog has a prop...

Regular expression to match non-english characters?

What is the easiest way to match non-english 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. ...

What regEx can I use to Split a string into whole words but only if they start with # ?

I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item("Post"), "\b\#\b") But it is splitting all words, I want an array of words that start with# Thanks! ...

Ruby - Regex String Insertion

I need to substitute the value of a string into my regular expression in Ruby. Is there an easy way to do this? For example: foo = "0.0.0.0" goo = "here is some other stuff 0.0.0.0" if goo =~ /foo's value goes here/ puts "success!" end ...

Are regexes really maintainable?

Any code I've seen that uses Regexes tends to use them as a black box: Put in string Magic Regex Get out string This doesn't seem a particularly good idea to use in production code, as even a small change can often result in a completely different regex. Apart from cases where the standard is permanent and unchanging, are regexes th...

.Net Regex ValidationExpression ASCII

Anyone know a good Regex expression to drop in the ValidationExpression to be sure that my users are only entering ASCII characters? <asp:RegularExpressionValidator id="myRegex" runat="server" ControlToValidate="txtName" ValidationExpression="???" ErrorMessage="Non-ASCII Characters" Display="Dynamic" /> ...

Perform regex (replace) in an SQL query

What is the best way to replace all '&lt' with &lt; in a given database column? Basically perform s/&lt[^;]/&lt;/gi Notes: must work in MS SQL Server 2000 Must be repeatable (and not end up with &lt;;;;;;;;;;) ...

Looking for a regular expression including aplhanumeric + "&" and ";"

Here's the problem: split=re.compile('\W*') works fine when dealing with regular words, but there are occasions where I need the expression to include words like k&auml;ytt&auml;jauml;. What should I add to the regex to include the & and ; characters? ...

Concatenate RTF files in PHP (REGEX)

Hi Team, I've got a script that takes a user uploaded RTF document and merges in some person data into the letter (name, address, etc), and does this for multiple people. I merge the letter contents, then combine that with the next merge letter contents, for all people records. Affectively I'm combining a single RTF document into itsel...

In a java regex, how can I get a character class e.g. [a-z] to match a - minus sign?

Pattern pattern = Pattern.compile("^[a-z]+$"); String string = "abc-def"; assertTrue( pattern.matcher(string).matches() ); // obviously fails Is it possible to have the character class match a "-" ? ...

Multi-Line group and search with Regex

Ok, Regex wizards. I want to be able to search through my logfile and find any sessions with the word 'error' in it and then return the entire session log entry. I know I can do this with a string/array but I'd like to learn how to do it with Regex but here's the question. If I decide to do this with Regex do I have one or two problem...

.NET - How can you split a "caps" delimited string into an array?

How do I go from this string: "ThisIsMyCapsDelimitedString" ...to this string: "This Is My Caps Delimited String" Fewest lines of code in VB.net is preferred but C# is also welcome. Cheers! ...

What GNU/Linux command-line tool would I use for performing a search and replace on a file?

What GNU/Linux command-line tool would I use for performing a search and replace on a file? Can the search text, and replacement, be specified in a regex format? ...

Perl: Grabbing the nth and mth delimited words from each line in a file

Because of the more tedious way of adding hosts to be monitored in Nagios (it requires defining a host object, as opposed to the previous program which only required the IP and hostname), I figured it'd be best to automate this, and it'd be a great time to learn Perl, because all I know at the moment is C/C++ and Java. The file I read...

Is there a way to retrieve only a portion of a matched string using regex in Javascript?

Say I've got a string, "foo (123) bar", and I want to retrieve all numbers surrounded by the delimiters "(" and ")". If I use varname.match(/\([0-9]+\)/), my delimeters are included in the response, and I get "(123)" when what I really want is "123". Is there a way I can retrieve only a portion of the matched string without following it ...

Regexp recognition of email address hard?

I recently read somewhere that writing a regexp to match an email address, taking into account all the variations and possibilities of the standard is extremely hard and is significantly more complicated than what one would initially assume. Can anyone provide some insight as to why that is? Are there any known and proven regexps tha...

How do I specify IP Ranges (RegEx) for SkipHosts in AWStats config files?

I'm updating some old AWStats config files to filter out some specific IP ranges. Here's the pertinent section of the config file: # Do not include access from clients that match following criteria. # If your log file contains IP addresses in host field, you must enter here # matching IP addresses criteria. # If DNS lookup is already do...