regex

How can I extract all conversations in a Postfix log from a particular client using awk?

I am trying to extract conversations from a Postfix log file based on the client that initiated them. This is the awk script that extracts the matching message IDs: awk '/client.host.name/ && !(/timeout/||/disconnect/) { sub(":","",$6);print $6}' maillog This is using a standard Postfix maillog as input (see below for sample data). Wha...

How do I get the following regular expression to not allow blank e-mails?

I am using the following regular expression to validate e-mails, but it allows empty strings as well, how can I change it to prevent it: ^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$ I am using an asp:RegularExpressionValidator. My other option is to add on a asp:RequiredFieldValidator, but I am curious if th...

preg_match in JavaScript ?

Hello ! Is it possible in JavaScript to do something like preg_match does in PHP ? I would like to be able to get two numbers from string: var text = 'price[5][68]'; into two separated variables: var productId = 5; var shopId = 68; Edit: I also use MooTools if it would help. ...

Unreliable javascript regex test in Firefox and Chrome

I am encountering a strange javascript regex problem on Firefox 3.6 and Chrome 6 dev. I am working on a massive form entry website that has some basic javascript validation using jQuery. $(document).ready(function() { $("tr[id^='" + BaseRowId + "rid']").each(function(){obj.WireRowEvents(this);}); } var obj = { "WireRowEvents": funct...

Making a custom validator with regex..not triggering yet

Hey guys, I thought this would be fairly straightforward, but it's not it seems..maybe I'm just writing the syntax wrong.. In my model I'm checking for certain key words before_validation :deal_validation def deal_validation if self.description.match /(exp\s|expire|ex\s|print|mention|\/)/ errors.add(:description, "Now just a se...

Problems getting rid of multiple periods in a FileName

I am trying to take file names that look like: MAX_1.01.01.03.pdf look like Max_1010103.pdf. Currently I have this code: public void Sanitizer(List<string> paths) { string regPattern = (@"[~#&!%+{}]+"); string replacement = " "; Regex regExPattern = new Regex(regPattern); Regex regExPattern2 = new Regex(@"\s{2,}"); Rege...

regex.h print the subexpression

I want to extract a substring from my expression using regex.h library in C. Here is the code #include <regex.h> #include <stdio.h> #include <stdlib.h> int main(void) { regex_t preg; char *string = "Random_ddName:cateof:Name_Random"; char *pattern = ".*Name:\\(.*\\):Name.*"; int rc; size_t ...

Regex: how do I capture the file extension?

How do I determine the file extension of a file name string? lets say I have I'm.a.file.name.tXt the regex should return tXt ...

Where is a reference to regex header on MSDN?

I can include this file directly now without tr1 in VS 2010 but can't find description of this file anywhere on MSDN. Where is a reference to regex header on MSDN? ...

Ruby: How do I capture part of a string with regex?

I have file_ext = attach.document_file_name.capture(/\.[^.]*$/) but i guess there is no method capture. I'm trying to get the file extension from a string. I don't yet have the file. ...

String contains only a given set of characters

I need to know if a given string is a valid DateTime format string because the string may represent other things. I tried DateTime.ParseExact(somedate.ToString(format), format) thinking it would barf on an invalid format, but it doesn't. So I'm good with simply testing if the string contains only "yYmMdDsShH" characters. Something like ...

Help with a regex expression

I am trying to get the word after Sysdba. out of a string. Here is a example where my result would be PRODUCTION CAST(CASE WHEN SYSDBA.PRODUCTION.SHIPPING_COMPLETE_DATE IS NOT NULL THEN 1 ELSE 0 END AS bit) AS [Shiping Completed]] I created the regex expression Regex CatagoryRegex = new Regex(@"SYSDBA\.(.#)\.", RegexOptions.IgnoreCa...

js regex escaping quotes

I want to escape all quotes that comes only after the text H1: For instance, : H1: "text here" should become: H1: &quot;text here&quot; This would be easy with lookbehind, but that's not in JS. something I tried: .replace(/H1:(.*)(")(.*)/ig, "H1:$1&quot;$2") Also it should work on other similar text like: H1: ""text here"" H1...

Javascript: highlight substring keeping original case but searching in case insensitive mode

Hi everybody, I'm trying to write a "suggestion search box" and I cannot find a solution that allows to highlight a substring with javascript keeping the original case. For example if I search for "ca" I search server side in a case insensitive mode and I have the following results: Calculator calendar ESCAPE I would like to view t...

preg_replace to strip out non-printing characters seems to remove all foreign characters as well

I'm using the following regex to strip out non-printing control characters from user input before inserting the values into the database. preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $value) Is there a problem with using this on utf-8 strings? It seems to remove all non-ascii characters entirely. ...

How to use Perl to parse specified formatted text with regex?

Dear Perl gurus: Question abstract: how to parse text file into two "hashes" in Perl. One store key-value pairs taken from the (X=Y) part, another from the (X:Y) part? 1=9 2=2 3=1 4=6 2:1 3:1 4:1 1:2 1:3 1:4 3:4 3:2 they are kept in one file, and only the symbol between the two digits denotes the difference. ==...

PHP code for checking email says .info domains are invalid

I have the following PHP code that checks if an email is valid: if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2}[mtgvu]?$", $email)) return true; Works great but I found out today that if I try validate a .info email, it says it's invalid. Any ideas what I need to add/modify to make it return .info e...

XSD regex failed validate: Unexpected meta character

Hi all, This snippet <xsd:element name="HomePhone" minOccurs="0"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:pattern value="^+[0-9]{1,2}-[0-9]{1,2}-[0-9]{3}[0-9]{0,1}-[0-9]{3}[0-9]{0,1}$"></xsd:pattern> </xsd:restriction> </xsd:simpleType> </xsd:element> is returning th...

What is a regular expression that will remove all "function foo() { ... }" and show other content?

That is, given a Javascript file, this regular expression can show only the "immediate execution" of code, removing all the function definitions in the form of function foo() { ... } Or can regular expression find the "matching { }" because there can many nested { } ...

Regex Pop Quiz Question of the Day

Suppose I want to turn this : http://en.wikipedia.org/wiki/Anarchy into this : en.wikipedia.org or even better, this : wikipedia.org Is this even possible in regex? ...