regex

RegularExpressionValidator Expression needed

Hi all, i am using asp.net 3.5 and VB.net, i need a validation expression to validate a string of 1 to 50 characters, white spaces, numbers, special character are all allowed, simply, it should match an nvarchar(50) database field. it will be applied to a textbox, also, the same case but for 1-200 characters which will be validating a mu...

Regexp pattern matching IP and UserAgent in an Huge File

Hi, all. I have a huge log file that has a structure like this: ip=X.X.X.X userAgent=Firefox ----- Referer=hxxp://www.bla.org I want to create a custom output like this: ip:userAgent for ex: X.X.X.X:Firefox and the pattern will ignore lines which don't start with ip= and userAgent=. (these two must form a pair as i mentioned abov...

Using a regular expression to match each individual character as it's own group?

In PHP I'm trying to match each character as its own group. Which would mimic the str_split(). I tried: $string = '123abc456def'; preg_match_all('/(.)*/', $string, $array); // $array = array(2) { // [0]=> array(2) { // [0]=> string(12) "123abc456def" // [1]=> string(0) "" } // [1]=> array(2) { [0]=> string(1) "f" [...

Regex to insert newlines into large block of text at specific locations

I have a rather large text file that has a bunch of missing newlines, meaning that it's a mess. I need to break it up into appropriate lines. The text looks something like this now: 12345 This is a chunk 23456 This is another chunk 34567 This is yet another chunk 45678 This is yet more chunk 56789 Yet another piece of text I need a r...

What is the most correct regular expression for a UNIX file path?

What is the most correct regular expression (regex) for a UNIX file path? For example, to detect something like this: /usr/lib/libgccpp.so.1.0.2 It's pretty easy to make a regular expression that will match most files, but what's the best one, including one that can detect escaped whitespace sequences, and unusual characters you don'...

How do I find similar column names using linq?

Hi I am trying to learn Linq, so I am not sure if this can be done. I am working on an import project So I decided to import data using DataSets. My challenge at this point: Having 2 DataTables with different schema, one of which contains my destination schema, and the other one my source schema. What I need to do is perform some...

Are Java and C# regular expressions compatible?

Both languages claim to use Perl style regular expressions. If I have one language test a regular expression for validity, will it work in the other? Where do the regular expression syntaxes differ? The use case here is a C# (.NET) UI talking to an eventual Java back end implementation that will use the regex to match data. Note that...

emacs - regular expressions in lisp need to be double-escaped...why?

I've been playing around with emacs lisp, and I wanted to write a little function to do a regular expression search and replace. I had a heck of a time getting the regular expression to work correctly because I didn't realize that all the special characters need to be double escaped when writing lisp code (but not when using query-repla...

Looking for a URI match on this regular expression, but it is crashing regex testers

I'm trying to use this regular expression, but I'm having trouble testing it, because for whatever reason it is crashing the only two regex testers I use. ^([a-zA-Z-]+/?)+$ If I'm not mistaken, that should match any URI that follows this format: some-uri-string/some-uri-string/some-uri-string However, I don't want it to match: some-...

Isn't it possible to use 'Repeats' in the lookaheads for boost:regex?

I'm trying to extract some variables in my C++ code nested in blocks for example, if I have DEL_TYPE_NONE, DEL_TYPE_DONE, DEL_TYPE_WAIT, I'd like to match "DEL_TYPE_NONE" "DEL_TYPE_DONE" "DEL_TYPE_WAIT" I made my pattern like this, std::string pat("(?<=^[ \\t]?)[A-Z0-9_]+(?=,$)"); but I'm keep getting error message when compil...

How to get a regular expression to match items with spaces

The following regular expression works if there is no space character, but if the input has a space character, it doesn't work (it seems like a link but JavaScript doesn't work). How can I change it? The regular expression should work for both World and The World. Dim makebkz As String Dim pattern As String = "\(bkz: ([a-z0-9...

Looking for some URL rewriting help

Hi everyone, My question is a simple one, but I can't seem to find the answer. I'm currently working on some URL rewriting for a website, but I have encountered a problem. Currently the most basic rule I have goes something like this: RewriteRule ^([a-zA-Z]+)/(([a-zA-Z]+)/?$ index.php?mod=$1&com$2 This works in most cases, and I have...

In Javascript, how can i perform a global replace on string with a variable inside '/' and '/g'?

Hi to all. I want to perform a global replace of string using String.replace in Javascript. In the documentation i read that i can do this with /g, i.e. for example; var mystring = mystring.replace(/test/g, mystring); and this will replace all occurrences inside mystring. No quotes for the expression. But if i have a variable to f...

Regex to Indent an XML File.

Is it possible to write a REGEX (search replace) that when run on an XML string will output that XML string indented nicely? If so whats the REGEX :) ...

How would I write a Java regex that gets the contents of a <script> tag?

I'm trying to integrate analytics into my GWT application. To do this, I'm calling a service that returns a String of HTML that needs to be parsed and eval'ed. I need a regex that looks for and grabs either 1) the body of the tag or 2) the contents of the "src" attribute. I want to eval both of these with JavaScript. I'm happy with as...

Replacing tags with content in a simple template system

I'm trying to build a simple "User Template" system so that my users can edit the layout of RSS feed items and system-generated emails without messing with view files and such. This is the function I'm using to replace the tags in a string with content: private const string URL_TAG_REGEX = @"{{(?<TagName>\w*)}}"; private static string R...

How do you write and test your regular expressions?

Is their any wizards or tools to create and test regular expressions for PHP, because it is so difficult :( ? thanks :) ...

Problem With Regular Expression to Remove HTML Tags

In my Ruby app, I've used the following method and regular expression to remove all HTML tags from a string: str.gsub(/<\/?[^>]*>/,"") This regular expression did just about all I was expecting it to, except it caused all quotation marks to be transformed into &#8220; and all single quotes to be changed to &#8221; . What's the obviou...

ASP.Net Mapping Values Lookup.

Currently in my ASP.Net applications web.config I have an application setting that stores a comma delimited list of mapping values, like the one below. In the code behind I need to perform a lookup on this data based on input values 1, 2, 3 etc. I can either string split it and loop until I find a match, or use Regex to pull the value fr...

Regular expression that returns a constant value as part of a match

I have a regular expression to match 2 different number formats: \=(?[0-9]+)\?|\+(?[0-9]+)\? This should return 9876543 as its Value for ;1234567890123456?+1234567890123456789012345123=9876543? and ;1234567890123456?+9876543? What I would like is to be able to return another value along with the matched 'Value'. So, for example, if t...