regex

BNF to regular Expressions

How can I describe the language A → AA | ( A ) | ε generates using regular expressions? ...

How can I match quoted text excluding leading and trailing whitespaces?

I.e. the match of He said, "For my part, it was Greek to me. " should be For my part, it was Greek to me. Without the trailing space. I've tried \"\s*([^\"]*)\s*\" but it's always matching trailing whitespaces in the group. ...

Regex to Extract Update Columns from a Sql Statement

I need a Regex Statement (run in c#) that will take a string containing a Sql Update statement as input, and will return a list of columns to be updated. It should be able to handle columns surrounded by brackets or not. // Example Sql Statement Update Employees Set FirstName = 'Jim', [LastName] = 'Smith', CodeNum = codes.Num From Empl...

How to prevent Sql-Injection on User-Generated Sql Queries

I have a project (private, ASP.net website, password protected with https) where one of the requirements is that the user be able to enter Sql queries that will directly query the database. I need to be able to allow these queries, while preventing them from doing damage to the database itself, and from accessing or updating data that th...

Regex to block all < in a String

I'm trying to create a Regex to block all < and > in a String except when used with <select>. Can anyone suggest a Regex for that? I'll be using it with javax.util.Pattern. I'm trying to write a solution to block the injection attack and XSS attempts through request and URL. For that, I'll be blocking the special characters and charact...

Best regex library for iphone sdk app?

Hi, I'm confused about the regex librarys that can be available for the iphone. For example RegexLite look like need a dinamyc link, nad as I understood this is not possible for the sdk on the iPhone. I wanna a regex library for do data validation... which one is the best available? ...

Regular Expression in Python - Parsing html

I need to search through an html doc, find all of the spans and delete the spans and everything between them. What would a regular expression look like that would match everything between ? ...

Create regex from glob expression

Hi, i write program that parse text with regular expression. Regular expression should be obtained from user. I deside to use glob syntax for user input, and convert glob string to the regular expression internally. For example: "foo.? bar*" should be converted to "^.*foo\.\w\bar\w+.*" Somehow, i need to escape all meaningful cha...

regular expression for no blank space b/w text

Please tell me how to check regular expression for no blank space b/w text. ...

Regex match and grouping

Here's a sample string which I want do a regex on 101-nocola_conte_-_fuoco_fatuo_(koop_remix) The first digit in "101" is the disc number and the next 2 digits are the track numbers. How do I match the track numbers and ignore the disc number (first digit)? ...

Python's re module - saving state?

Hi, One of the biggest annoyances I find in Python is the inability of the re module to save its state without explicitly doing it in a match object. Often, one needs to parse lines and if they comply a certain regex take out values from them by the same regex. I would like to write code like this: if re.match('foo (\w+) bar (\d+)', li...

Matching exact string with javascript

How can I test if a regex matches a string exactly? var r = /a/; r.test("a"); // returns true r.test("ba"); // returns true testExact(r, "ba"); // should return false testExact(r, "a"); // should return true ...

How can I remove middle initial with a dot at the end?

I've got a bunch of first names in a field that carry a middle initial with a '.' at the end..I need a regex to convert this example:Kenneth R.intoKennethI was trying to build my own and found this useful site btw..http://www.gskinner.com/RegExr/but I'm new to Perl & regular expressions and could only get "...$" - which is useless when t...

How to exclude from match if a substring of another string

I have a problem. I'd like to match all occurrences of \t in my text (and by \t i mean it literally it is not a tab character) but I would like to exclude a match if it is a part of \t string. How to do that? Example <HTML>Blah</HTML>\t D:\\UserData\\tui I'd like to match \t in the first line but not in second line (as it is a part o...

How do i write a Regular Expression to match text containing XYZ but not ABC?

I want to write a regex that matches if a string contains XYZ but doesn't contain ABC somewhere before it. So "blah XYZ blah" should match, but "blah ABC blah XYZ blah " should not. Any ideas? In particular I'm writing the regex in c#, in case there's anything specific to that syntax. I guess I can use negative lookbehind but haven't u...

How would I create a VIM or Vi command to delete all text after a certain character for every line in a text file?

Scenario: I have a text file that has pipe (as in the "|" character) delimited data. Each field of data in the pipe delimited fields can be of variable length, so counting characters won't work (or using some sort of substring function... if that even exists in VIM). Is it possible, using VIM / Vi to delete all data from the second p...

Using C# Regular expression to replace XML element content

I'm writing some code that handles logging xml data and I would like to be able to replace the content of certain elements (eg passwords) in the document. I'd rather not serialize and parse the document as my code will be handling a variety of schemas. Sample input documents: doc #1: <user> <userid>jsmith</userid> <p...

How can I change extended latin characters to their unaccented ASCII equivalents?

I need a generic transliteration or substitution regex that will map extended latin characters to similar looking ASCII characters, and all other extended characters to '' (empty string) so that... é becomes e ê becomes e á becomes a ç becomes c Ď becomes D and so on, but things like ‡ or Ω or ‰ just get striped away. ...

Help With Regular Expression

Hi, I am trying to write a pattern for extracting the path for files found in img tags in HTML. String string = "<img src=\"file:/C:/Documents and Settings/elundqvist/My Documents/My Pictures/import dialog step 1.JPG\" border=\"0\" />"; My Pattern: src\\s*=\\s*\"(.+)\" Problem is that my pattern will also include the 'border="0" p...

What is the correct regular expression for an email address?

Duplicate: http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses There seem to be an awful lot of different variants on this on the web and was wondering if there is a definitive answer? Preferably using the .net (Regex) dialog of regular expressions. ...