regex

How to select a file path using regex

I would like like to create a java regular expression that selects everything from file: to the last forward slash (/) in the file path. This is so I can replace it with a different path. <!DOCTYPE "file:C:/Documentum/XML%20Applications/joesdev/goodnews/book.dtd"/> <myBook>cool book</myBook> Does anyone have any ideas? Thanks!! ...

Parsing a WSDL to extract Service / Port elements

I want to automatically process a WSDL file to discover defined Service / Port elements. Is this possible, using Java or some sort of Ant utility? If so, how? ...

I need a regex for the href attribute for an mp3 file url in python

Hi, Based on a previous stack overflow question and contribution by cgoldberg, I came up with this regex using the python re module: import re urls = re.finditer('http://(.*?).mp3', htmlcode) The variable urls is an iterable object and I can use a loop to access each mp3 file url individually if there is more than one : for url in u...

Match Question Mark in mod_rewrite rule regex

I am looking to rewrite urls with multiple substrings. One substring is being requested as a subdirectory, while any others are requested as normal query string parameters. For example, I would like to rewrite urls from http://www.mysite.com/mark/friends?page=2 to http://www.mysite.com/friends.php?user=mark&amp;page=2 I am able t...

regular expression in javascript string split, browser compatibility issue

I've been investigating this issue that only seems to get worse the more I dig deeper. I started innocently enough trying to use this expression to split a string on HTML 'br' tags: T = captions.innerHTML.split(/<br.*?>/g); This works in every browser (FF, Safari, Chrome), except IE7 and IE8 with example input text like this: is inv...

.NET Regex fails to match in code, works in every testing harness

This one is a real head scratcher for me... var matches = Regex.Matches("<p>test something<script language=\"javascript\">alert('hello');</script> and here's <b>bold</b> and <i>italic</i> and <a href=\"http://popw.com/\"&gt;link&lt;/a&gt;.&lt;/p&gt;", "</?(?!p|a|b|i)\b[^>]*>"); The Regex is supposed to capture any HTML tag (open or cl...

Regular expression to parse xaml binding-esque syntax

As usual, regular expressions are causing my head to hurt. I have the following strings (as examples) which I would like to parse: Client: {Path=ClientName}, Balance: {Path=Balance, StringFormat='{0:0.00}'} Client: {Path=ClientName}, Balance: {Path=Balance, StringFormat='Your balance is {0:0.00}.'} I am looking for a regular expressi...

How can I return records with a MySQL query using a regular expression?

I have records in my database that are searched with user input, and initially, this was sufficient for finding the correct records. "SELECT id FROM plants WHERE Flower LIKE '%" . $sanitizedUserInput . "%'" This was working all well and good, but then things started to happen like, searching 'red' was getting plants with the character...

Using VI how can I search and replace for the following statement?

I need to replace the following: CREATE TABLE /*!32312 IF NOT EXISTS*/ `access` to CREATE TABLE IF NOT EXISTS `access` I've tried :%s/\/\*\!\d+(.*)\*\//\1/g But that didn't seem to go. What am I doing wrong? ...

Find/Replace Word Puzzle

Let's say I have an object that contains a Word property and a Sentence property. The sentence must use the word, and I want to replace the word in that sentence with a link using a public function (say, GetLinkedSentence). The catch is maybe the sentence uses a plural form of the word and maybe the "word" itself is actually a phrase, or...

How do I use regex to replace non-word chars in a specific piece of string?

I have text file with a row like this: SendersTimeSeriesIdentification: COMPANY_A/COMPANY_B/REF_7/20090505 I'd like to replace all non-word chars in the value part with the character n, like this: SendersTimeSeriesIdentification: COMPANYnAnCOMPANYnBnREFn7n20090505 But there are similar strings all over the file, which must remain i...

HTML Escaping - Reg expressions?

I'd like to HTML escape a specific phrase automatically and logically that is currently a statement with words highlighted with quotation marks. Within the statement, quotation or inch marks could also be used to describe a distance. The phrase could be: Paul said "It missed us by about a foot". In fact it was only about 9". T...

.Net Regular Expression Crashes aspnet_wp.exe

Hi, I'm having the following problem and wondered whether anyone could see why this is crashing my .net worker process (aspnet_wp.exe): Dim pattern As String = "\{\{IF\(((?!\)}})(.))+,,,((\s)*(?!\)}})(.))+\)}}" Dim mc As RegularExpressions.MatchCollection = Regex.Matches(txtContent.Text, pattern) Works absolutely fine if a match ...

How can you match words with more than one character?

I would like to use a regular expression to match all words with more that one character, as opposed to words entirely made of the same char. This should not match: ttttt, rrrrr, ggggggggggggg This should match: rttttttt, word, wwwwwwwwwu ...

Recursively reading an xml document and using regex to get contents

I have an xml document like the following: <menuitem navigateurl="/PressCentre/" text="&#1087;&#1088;&#1077;&#1089; &#1094;&#1077;&#1085;&#1090;&#1098;&#1088;"> <menuitem navigateurl="/PressCentre/RegisterForPressAlerts/" text="&#1088;&#1077;&#1075;&#1080;&#1089;&#1090;&#1098;&#1088; &#1079;&#1072; &#1087;&#1088;&#1077;&#1089; &#...

vim regex search csv string and paste matches

edit: I need advice on best way to search with regex in vim and extract any matches that are discovered. end edit. I have a csv file that looks something like this: two fields: id and description 0g98932,"long description sometimes containing numbers like 1234567, or 0000012345 and even BR00012345 but always containing text" I ...

A RegEx for: {0}

I feel like an idiot for asking this but what would a regular expression be to match the literal string: {0} This would be used in JavaScript with the string object's replace function. I've tried several things and nothing seems to work. Thanks, Frank ...

How do you validate a URL with a regular expression in Python?

I'm building a Google App Engine app, and I have a class to represent an RSS Feed. I have a method called setUrl which is part of the feed class. It accepts a url as an input. I'm trying to use the re python module to validate off of the RFC 3986 Reg-ex (http://www.ietf.org/rfc/rfc3986.txt) Below is a snipped which should work, right?...

Regex question to find a trailing space in a whole folder

Hi, I have a folder pulled from a wordpress installation, >1000 files. Some php code is throwing an error due to trailing spaces on the very last line (I cleaned up an iframe injection on some final lines of pages, and did find/replace with a space, but didn't know that that would throw off all my code). What's the most efficient way t...

Regular expression question

Hi, I am trying to use the cscope-indexer script. But I want to know how to change the following to include *.mm and *.java files? egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \ sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e 's/^\.\///' | \ sort > $LIST_FILE I tried egrep -i '\.([chly](xx|pp)*|cc|hh|mm|java)$' it does not work. ...