regex

php/regex: remove useless paragraph tags from string

if I have a string like <p>&nbsp;</p> <p></p> <p class="a"><br /></p> <p class="b">&nbsp;</p> <p>blah blah blah this is some real content</p> <p>&nbsp;</p> <p></p> <p class="a"><br /></p> how can I turn it into just <p>blah blah blah this is some real content</p> needs to pick up nbsps and regular spaces ...

How to take a phone number with a plus and bracket and just return the numbers?

Hey Everyone, I have a simple problem I have a phone like this: +1 (123) 123-1234 and I want to just take the numbers out of that string using regex. Any help will be greatly appreciated. Thanks ...

Javascript regex returning null but it shouldn't be. Why?

I have a regex that searches the source of a page it retrieves via Ajax and gets all the data inbetween and including the fieldset tags. Here's my javascript: var req = new XMLHttpRequest(); var regex = new RegExp("<(fieldset)\b[^>]*>.*?</\1>"); function showEditForm(i) { req.open('GET', '/admin/maps/edit/' + i, false); req....

Validate MSSQL identifier (parameter) in .NET or regular expression

In a .NET project I need to verify if a string is a valid Microsoft SQL Server 2005 parameter identifier. Example: SELECT * FROM table WHERE column = @parameter Is there a runtime class method to validate a string for being a parameter, or is there a regular expression that verifies the rules? (see below) From the documentation on ide...

Given a string, generate a regex that can parse *similar* strings

For example, given the string "2009/11/12" I want to get the regex ("\d{2}/d{2}/d{4}"), so I'll be able to match "2001/01/02" too. Is there something that does that? Something similar? Any idea' as to how to do it? ...

How can I keep only the first five lines in a Perl scalar?

From any kind of scalar, what regex could I use to match the first five lines of it and discard the rest? ...

Question about Java regex

I get a string from a array list: array.get(0).toString() gives TITLE = "blabla" I want the string blabla, so I try this : Pattern p = Pattern.compile("(\".*\")"); Matcher m = p.matcher(array.get(0).toString()); System.out.println("Title : " + m.group(0)); It doesn't work: java.lang.IllegalStateException: No match found I also t...

Replacing HTML attributes using a regex in PHP

OK,I know that I should use a DOM parser, but this is to stub out some code that's a proof of concept for a later feature, so I want to quickly get some functionality on a limited set of test code. I'm trying to strip the width and height attributes of chunks HTML, in other words, replace width="number" height="number" with a blank s...

Why doesn't this Java regular expression work?

I need to create a regular expression that allows a string to contain any number of: alphanumeric characters spaces ( ) & . No other characters are permitted. I used RegexBuddy to construct the following regex, which works correctly when I test it within RegexBuddy: \w* *\(*\)*&*\.* Then I used RegexBuddy's "Use" feature to conver...

RegEx for CSV validation + jQuery

Hello All, Using jQuery validation plugin but it has no CSV validation. I have made an additional validation for this but can't get the RegEx right. Here is what I have: jQuery.validator.addMethod("csv", function(value, element) { return this.optional(element) || /([\w.$]+?(,[\w.]+)+)/.test(value); }, "Must be comma separated if ent...

Is it possible to split the file contents using a custom pattern?

Hello, Is it possible to split the contents of file into parts that have specific pattern? This is what I want to achieve: Read the file using file_get_contents Read only contents between similar commented areas. I am not sure how complicated is that but basically If I am parsing a large html file and want only to display to the br...

regex for parsing SQL statements

I've got an IronPython script that executes a bunch of SQL statements against a SQL Server database. the statements are large strings that actually contain multiple statements, separated by the "GO" keyword. That works when they're run from sql management studio and some other tools, but not in ADO. So I split up the strings using the...

Get value between two substrings using regex

If I have a string "Param1=value1;Param2=value2;Param3=val3", how can I get the value between the substrings "Param2=" and the next semicolon (or end of string, whichever comes first)?" ...

Repetition of group patterns in a regex pattern

So, folks, I have this self crafted pattern that works. After some hours (I am no regex guru) this puppy evolved to parse curl PUT output for me: ^\s*([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+) \s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+) (CR in text only for formatting) It gives me 'groups' that...

Sed: Change case of substitution group

How can I change the case of a matching group from lower to uppercase with sed Unix command? Thanks Martin ...

regular expression to replace an xml attribute

I have an xml file of the form: <property name="foo" value="this is a long value">stuff</property> There are many properties but I want to match the one with name foo and then replace its value attribute with something else as so: <property name="foo" value="yet another long value">stuff</property> I was thinking to write a regular...

Tricky pattern match

This could be tricky, easy or impossible... I'm not sure I have a list of domains and I'm trying to match them as closely as possible to the website name in the "title" tag. For example... Domain: www.yahoo.com Title: Yahoo! Result: Yahoo! Domain: www.thegreenpages.com Title: Welcome to The Green Pages. Result: The Green Pages Do...

Parsing Large Text Files in Real-time (Java)

Hi all, I'm interested in parsing a fairly large text file in Java (1.6.x) and was wondering what approach(es) would be considered best practice? The file will probably be about 1Mb in size, and will consist of thousands of entries along the lines of; Entry { property1=value1 property2=value2 ... } etc. My first instinc...

Regex - Matching exactly one single tag

I have a regex to extract the text from an HTML font tag: <FONT FACE=\"Excelsior LT Std Bold\"(.*)>(.*)</FONT> That's working fine until I have some nested font tags. Instead of matching <FONT FACE="Excelsior LT Std Bold">Fett</FONT> the result for string <FONT FACE="Excelsior LT Std Bold">Fett</FONT> + <U>Unterstrichen</U> + <FO...

Regex Problem

Take the following contents of a file: "52245" "528" "06156903" "52246" "530" "00584709" What pattern would match both 52245 and 52246 but nothing else? ...