regex

i want to capture a single match

i want to capture only the first match through the expression <p>.*?</p> i have tried <p>.*?</p>{1} but it is not working it returns all the p tags which are in the html document, please help ...

Splitting a title into separate parts

Hi, I need a to split a string of the form 2,9.1,The Godfather (1972), (it's a csv line) to: 2 9.1 The Godfather 1972 any ideas for a good regular expression? BTW, if you know a good regular expressions creator based on examples you provide it'd be great. I'm a bit new to this.. 10x!! ...

Is there enough information to know what this regex is searching and replacing?

Could anyone explain what's being replaced here? I don't know if enough information is present to understand what's being searched and what's being replaced: regEx.Pattern = "(\s) *(\S)" regEx.Global = True that = regEx.Replace(that, "$1$2") ...

Replace newlines with BR tags, but only inside PRE tags

In stock PHP5, what is a good preg_replace expression for making this transformation: replace newlines with <br />, but only within <pre> blocks (Feel free to make simplifying assumptions, and ignore corner cases. For example, we can assume that tags will be one line, and not pathological things like ) Input text: <div><pre class='s...

What optimisations can I expect java.util.regex to perform?

Does Java perform any regex optimisations; if so, what are they? I'm interested in both optimisations at the regex engine level, and more general usage-level optimisations. (For example, in some other languages, commonly used regexes are cached to avoid re-compiling, but what I've read so far implies that Java doesn't do this automatic...

help with a preg_replace regular-expression

Hello all, I'm really confused as to using preg_replace but slowly learning. I need help with the function: $str= preg_replace('#\W\d+#', '\W \d+', $str); The idea is that Im looking for numbers that have letters directly before them with no spaces, ie abc123. (NOT 'abc 123' and NOT '123abc') and how do I simply include a space or...

Preg_match regex help

Hi there I need a bit of help. Here is the existing preg_match code: preg_match("/(\/)([0-9]+)(\/?)$/", $_SERVER["REQUEST_URI"], $m); which does a good job of detecting the post_id in the following URI string: http://www.example.com/health-and-fitness-tips/999/ I believe that should be enough background. I'm changing the 999, the...

Convert string to font & Color

Can somebody please help me with a regex (or something else), I'm really struggling to get this done and can't find anything anywhere that helps me to finish it. I have a program where the user places some controls on a form. and when they click the save button it goes through all controls on the form and saves their details to a text f...

regex.replace problem

I want do replace why this code don't work? MessageBox.Show( Regex.Replace(Regex.Escape(@"c:\www\html"), Regex.Escape(@"c:\www\"), "", RegexOptions.IgnoreCase)); ...

[C#] RegEx search for two pattern strings and cut what's between

I'm trying to write a little SQL Helper. I have a query like this stored in a string: DECLARE @V1 INT --ignore DECLARE @V11 INT DECLARE @V12 INT --endignore DECLARE @V2 INT --ignore SELECT * FROM SampleTable INNER JOIN AnotherSampleTable ...... --endignore SELECT * From Employee ORDER BY LastName My helper method should cut everyt...

Ruby: how to match a double quote in a regexp

I am trying to remove some double quotes (") characters from a text file using a Ruby one liner, with little success. I have tried the following, and some variations, without success. ruby -pe 'gsub(/\"/,"")' < myfile.txt This gives me the following error: -e:1: Invalid argument - < (Errno::EINVAL) I am running Ruby on a Win machi...

How to define {min,max} matches in treetop peg

With Ruby's regular expressions I could write /[0-9]{3,}/ I can't figure out how to write this in treetop other than: rule at_least_three_digit_number [0-9] [0-9] [0-9]+ end Is there a 'match [at least|most] n' rule for treetop? ...

Why RegExp with global flag in Javascript give wrong results?

What is the problem with this regular expression when I use the global flag and the case insensitive flag? Query is a user generated input. The result should be [true, true]. var query = 'Foo B'; var re = new RegExp(query, 'gi'); var result = []; result.push(re.test('Foo Bar')); result.push(re.test('Foo Bar')); // result will be [true, ...

Regex to detect Javascript In a string

Hello I am trying to detect JavaScript in my querystrings value. I have the following c# code private bool checkForXSS(string value) { Regex regex = new Regex(@"/((\%3C)|<)[^\n]+((\%3E)|>)/I"); if (regex.Match(value).Success) return true; return false; } This works for detecting <script></sc...

Regular expression for removing quotes from quoted numbers in a string

Let's say I have a bunch of text like this (simplified example, but you get the idea): INSERT stuff(a,b,c) VALUES('1','a','1'); INSERT stuff(a,b,c) VALUES('2','b','1'); INSERT stuff(a,b,c) VALUES('3','c','2'); INSERT stuff(a,b,c) VALUES('4','d','2'); INSERT stuff(a,b,c) VALUES('5','e','3'); INSERT stuff(a,b,c) VA...

Get Root Domain of Link

I have a link such as http://www.techcrunch.com/ and I would like to get just the techcrunch.com part of the link. How do I go about this in python? ...

jQuery Validator, Regex, and null

I am using jquery-1.3.2.js with the jquery.validate.js plugin and I am using the following code to try and validate an optional time field. $.validator.addMethod('time', function(value) { return /(^([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])(\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)|(^([0-9]|[1][0-9]|[2][0-3])(\s{0,1})(AM|PM|am|pm|aM|Am...

Match XML Attribute by Attribute Name? XSLT

How can I find attribute values based on a regular expression of the attribute name in xslt? In this snippet, I am trying to match attributes like "url.title", or "page.title", etc... anything with ".title". <attribute name="withRegexp"> <value-of select='matches(@*[name()], "\.title")'/> </attribute> That doesn't work, any ideas ...

Regex to match a minimum of 1 special character

I have the following regex that requires 1 number, 1 letter upper and 1 letter lower (w/ a minimum of 8 length) Regex.IsMatch(password, "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{8,}$") I need to add another filter to ensure one of the following special characters is present (any help?) #, $, @, !, %, &, * ? ...

Is there a library that provides static analysis of regular expressions?

Specifically, is there a library that, when given 2 (or more) regular expressions, can tell if exists an input that both would match? Bonus points if it's easily accessible via Java or .NET, but command-line would be fine as well. Asker's log, supplemental: The regular expressions that would be fed to this algorithm are fairly simple....