regex

Writing a simple preg_replace in PHP

Hey folks - I'm not much of a coder, but I need to write a simple preg_replace statement in PHP that will help me with a wordpress plugin. Basically I need code that will search for a string, pull out the video id, and return the embed code with the video id inserted into it. So in other words... I'm searching for this: [youtube=htt...

Storing PCRE compiled regexes in C/C++

Is there an efficient way to store the compiled regexes (compiled via regcomp(), PCRE) in a binary file, so that later I can just read from the file and call regexec()? Or is it just a matter of dumping the compiled regex_t structs to the file and reading them back when needed? ...

What's the best way to validate a user-entered URL in a Cocoa application?

I am trying to build a homebrew web brower to get more proficient at Cocoa. I need a good way to validate whether the user has entered a valid URL. I have tried some regular expressions but NSString has some interesting quirks and doesn't like some of the back-quoting that most regular expressions I've seen use. ...

Efficiently querying one string against multiple regexes.

Lets say that I have 10,000 regexes and one string and I want to find out if the string matches any of them and get all the matches. The trivial way to do it would be to just query the string one by one against all regexes. Is there a faster,more efficient way to do it? EDIT: I have tried substituting it with DFA's (lex) The problem he...

SQL Server Regular expressions in T-SQL

Is there any regular expression library written in T-SQL (no CLR, no extended sp, pure t-sql) for SQL Server? (should work with shared hosting) Edit: thanks I know about PATINDEX, LIKE, xp_ sps and CLR solutions I also know it is not the best place for regex, the question is theoretical:) reduced functionality is also accepted ...

Does this set of regular expressions FULLY protect against cross site scripting?

What's an example of something dangerous that would not be caught by the code below? EDIT: After some of the comments I added another line, commented below. See Vinko's comment in David Grant's answer. So far only Vinko has answered the question, which asks for specific examples that would slip through this function. Vinko provided...

Match Regex with Javascript

I need to match something in the form <a href="pic/5" id="piclink"><img src="thumb/5" /></a> to find the number, in this case 5, using javascript. I have no idea how to use regexes so I was wondering if anyone here could help out. Thanks! ...

How to parse a command line with regular expressions?

I want to split a command line like string in single string parameters. How look the regular expression for it. The problem are that the parameters can be quoted. For example like: "param 1" param2 "param 3" should result in: param 1, param2, param 3 ...

Help with a regex that matches something either before OR after something else

I have a bunch of XML that has lines that look like this <_char font_name="/ITC Stone Serif Std Bold" italic="true" /> but sometimes look like this <_char font_size="88175" italic="true" font_name="/ITC Stone Serif Std Bold" /> Here's what I need to do Replace italic="true" with italic="false for every line that contains ITC Ston...

RegEx to tell if a string does not contain a specific character

Easy question this time. I'm trying to test whether or not a string does not contain a character using regular expressions. I thought the expression was of the form "[^x]" where x is the character that you don't want to appear, but that doesn't seem to be working. For example, Regex.IsMatch("103","[^0]") and Regex.IsMatch("103&","...

Asp.NET Regular Expression Validator (Password Strength)

I have a validation control that has the following expression: (?=(.*\\d.*){2,})(?=(.*\\w.*){2,})(?=(.*\\W.*){1,}).{8,} That's a password with atleast 2 digits, 2 alpha characters, 1 non-alphanumeric and 8 character minimum. Unfortunately this doesn't seem to be cross-browser compliant. This validation works perfectly in Firefox but ...

I'm looking for a pythonic way to insert a space before capital letters.

I've got a file whose format I'm altering via a python script. I have several camel cased strings in this file where I just want to insert a single space before the capital letter - so "WordWordWord" becomes "Word Word Word". My limited regex experience just stalled out on me - can someone think of a decent regex to do this, or (better...

What's a good way to process RTF-encoded files and convert them to XML?

I have never done huge amounts of RTF processing, I always used a library to read or generate one and that was a long time ago. Now I need to get more intimate with the format again, and eventually convert it to XML. Can you recommend a good path to do it so that I have a lot of control on how RTF chunks are parsed and processed? Initi...

Regex for specifig tags and their content, groupped by the tag name

Here is the input (html, not xml): ... html content ... <tag1> content for tag 1 </tag1> <tag2> content for tag 2 </tag2> <tag3> content for tag 3 </tag3> ... html content ... I would like to get 3 matches, each with two groups. First group would contain the name of the tag and the second group would contain the inner text of the tag....

How do I write a .Net Regular Expression to match from the end of line back

I have the following line of text Reference=*\G{7B35DDAC-FFE2-4435-8A15-CF5C70F23459}#1.0#0#..\..\..\bin\App Components\AcmeFormEngine.dll#ACME Form Engine and wish to grab the following as two separate capture groups: AcmeFormEngine.dll ACME Form Engine Can anyone help? ...

What is the best regular expression for validating email addresses?

Over the years I have slowly developed a regular expression that validates MOST email addresses correctly, assuming they don't use an IP address as the server part. Currently the expression is: ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$ I use this in several PHP programs, and it works most of the time. How...

Regular expression that calls string "a?c" invalid?

In my user model, I have an attribute called "nickname" and validates as such: validates_format_of :nickname, :with => /[a-zA-Z0-9]$/, :allow_nil => true However, it is currently letting this string pass as valid: a?c I only want to accept alphanumeric strings - does anyone know why my regular expression is failing? If anybody c...

How do I match only fully-composed characters in a Unicode string in Perl?

I'm looking for a way to match only fully composed characters in a Unicode string. Is [:print:] dependent upon locale in any regular expression implementation that incorporates this character class? For example, will it match Japanese character 'あ', since it is not a control character, or is [:print:] always going to be ASCII codes 0x20...

Is there a Perl function to turn a string into a regexp to use that string as pattern?

I have trouble using Perl grep() with a string that may contain chars that are interpreted as regular expressions quantifiers. I got the following error when the grep pattern is "g++" because the '+' symbols are interpreted as quantifiers. Here is the output of for program that follows: 1..3 ok 1 - grep, pattern not found ok 2 - grep,...

Regex for SQL WHERE clause

For a web application I want to build a WHERE clause AND submit it to the server. There I will append it to a query. the clause will be something like LASTNAME LIKE 'Pep%' AND (DOB BETWEEN '19600101' AND '19601231 OR SALARY<35000) Can you propose a regular expression to validate the clause before submitting it to SQL Server? (Yes, of ...