('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?
...
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?
...
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?
...
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...
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.
...
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!
...
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
...
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...
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" />
...
What is the best way to replace all '<' with < in a given database column? Basically perform s/<[^;]/</gi
Notes:
must work in MS SQL Server 2000
Must be repeatable (and not end up with <;;;;;;;;;)
...
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äyttäjauml;.
What should I add to the regex to include the & and ; characters?
...
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...
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 "-" ?
...
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...
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?
Can the search text, and replacement, be specified in a regex format?
...
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...
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 ...
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...
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...