regex

How can I see if one string loosely contains another (case, extra whitespace, and punctuation ignored)?

I am writing a program in C# that compares strings similarly to the way that Google searches documents for keywords. I am wanting a search for "stack overflow" to return true for "stack overflow" (plain), "This is the stack overflow." (in the middle), "Welcome to Stack Overflow." (case insensitive), "I like stack overflow." (variable w...

match two strings with letters in random order in python

if I have 2 strings like: a = "hello" b = "olhel" I want to use a regular expression (or something else?) to see if the two strings contain the same letters. In my example a would = b because they have the same letters. How can this be achieved? ...

Regular Expression to validate short and long date in mm/dd/yyyy format in javascript

Hi all, I wanna validate date which can be either in short date format or long date format. eg: for some of the valid date. 12/05/2010 , 12/05/10 , 12-05-10, 12-05-2010 var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/; var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/; var valid = (reLong.test(entry)) || (reShort.test(entry)); if(valid...

What is wrong with my date regex?

var dateRegex = /\/Date\((\d+)\)\//g; // [0-9] instead of \d does not help. dateRegex.test("/Date(1286443710000)/"); // true dateRegex.test("/Date(1286445750000)/"); // false Both Chrome and Firefox JavaScript consoles confirm. What the hell, guys? Edit: even simpler test case: var dateRegex = /Date\(([0-9]+)\)/g; dateRegex.test("...

regex to pull out strings inside #if debug #endif block

Hi I have an application with a large number of #if debug blocks which kind of look like the the one below: #if DEBUG Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("oldXml: " + oldXml.OuterXml); Logging.Log("XmlDiff: " + diff_sb.ToString()); ...

Regular Expression- Help needed

Dear All, I have a String template from which I need to get the list of #elseif blocks. For example the first #elseif block will be from #elseif ( $variable2 )Some sample text after 1st ElseIf. ,second #elseif block is from #elseif($variable2)This text can be repeated many times until do while is called. SECOND ELSEIF and so on. I'm...

Why aren't modern regular expression dialects regular?

I've seen a few comments here that mention that modern regular expressions go beyond what can be represented in a regular language. How is this so? What features of modern regular expressions are not regular? Examples would be helpful. ...

How do I read a CSV file containing non-ASCII characters in Perl?

I am using Text::CSV to parse a csv file. Not all lines can be parsed, because of some bad characters. The Text::CSV documentation says: Allowable characters within a CSV field include 0x09 (tab) and the inclusive range of 0x20 (space) through 0x7E (tilde). How can I filter out as easy as possible any not-allowed characters? ...

Regex e-mail validating with Æ Ø Å

Hello. I need to validate a email address the best way, and I need to include some danish characters: Æ Ø Å æ ø å My current regex is: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* How to incorporate the extra letters, and is there any optimizing that can be done to ensure the best handling of the e-mail address? ...

Javascript Regex Tester for Javascript Regex

Hi, did anybody know a good regex tester for javascript (i think there are differents between php regex and javascript? right?) Thanks in advance! Peter ...

Javascript regex question

Hi all: What's the intent of () inside the regex? Thanks. pattern.replace(/\{(\d+)\}/g, function(pattern, index) { return args[index].toString(); }); PS: args is something like ["3", "dl1", "42"] ...

php regular expression for validating password with wild characters

I am trying to add wild characters to my current alphanumeric only regular expression to make the password validation stronger. I am not trying to require the user to enter wild characters, just allowing them to enter wild characters. '/^[a-z0-9]{8,16}$/i' I am also using cakephp and doing the validation in the model if that helps, bu...

werid, same expression yield different value when excuting two times in irb

irb(main):051:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id > ?" irb(main):052:0> "ts_id < what".gsub(/(=|<|>)\s?(\w+|\?)/,"#{$1} ?") => "ts_id < ?" Can anyone enlighten me? ...

I need a regular expression to find a string that's not commented out

my regular expression is currently: includes.push\("([^\"\"]*\.js)"\) but it matches all of the following lines /*includes.push("javascriptfile.js")*/ /* includes.push("javascriptfile.js") */ includes.push("javascriptfile.js"); includes.push("javascriptfile.js") And I don't want it to match the lines within comments. Any regex exp...

How to replace last occurrence of characters in a string using javascript

Hi I'm having a problem finding out how to replace the last ', ' in a string with ' and ': Having this string: test1, test2, test3 and I want to end out with: test1, test2 and test3 I'm trying something like this: var dialog = 'test1, test2, test3'; dialog = dialog.replace(new RegExp(', /g').lastIndex, ' and '); but it's not w...

regex to remove the webpage part of a url in ruby

I am trying to remove the webpage part of the URL For example, www.example.com/home/index.html to www.example.com/home any help appreciated. Thanks ...

How bad is my regex?

Ok so I managed to solve a problem at work with regex, but the solution is a bit of a monster. The string to be validated must be: zero or more: A-Z a-z 0-9, spaces, or these symbols: . - = + ' , : ( ) / But, the first and/or last characters must not be a forward slash / This was my solution (used preg_match php function): "/^[a-z\...

Searching all files for regex matching files on FTP server in C#.NET

I'm creating a program where I need to search an FTP server and download all files which match a given regex. How do I do this? I can connect to the FTP server, but how do I scan all files in the given path for files matching the regex? I also need to do the same for HTTP servers which I think will be fundamentally more difficult, but I...

javascript pattern replacement using backreference is not working

string.replace(/([\t])/g,"\\$1") is working fine where string.replace(/([\n])/g,"\\$1") is not working!!! any idea please??? N.B. string.replace(/\n/g,"\\n") is also working fine ...

How do I perform general pattern assignments in Perl?

$ cat names projectname_flag_jantemp projectname_flag_febtemp projectname_flag_marchtemp projectname_flag_mondaytemp $ Perl code: my $infile = "names"; open my $fpi, '<', $infile or die "$!"; while (<$fpi>) { my $temp = # what should come here? # func($temp); } I want temp to have jan feb march monday respectively. The p...