regex

Regex spanning over multiple lines / recognzing commented lines

Hi, i want to parse VB6 code via Regex. However being new to Regex I have encountered a few problems concerning the regexes to use. Currently, I have problems recognizing these constructs: ' Subs ' Sub Test Private Sub Test(ByVal x as Integer) 'Private Sub Test(ByVal y as Integer) Dim dummy as String dummy = "Private Sub Te...

How to run a dictionary search against a large text file?

We're in the final stages of shipping our console game. On the Wii we're having the most problems with memory of course, so we're busy hunting down sloppy coding, packing bits, and so on. I've done a dump of memory and used strings.exe (from sysinternals) to analyze it, but it's coming up with a lot of gunk like this: ''''$$$$ %%%% ...

Expression up to comment or end of line

Although this question is similar to this thread I think I might be doing something wrong at the time of constructing the code with the Regular Expression. I want to match anything in a line up to a comment ("#") or the end of the line (if it doesn't have a comment). The regex I am using is: (.*)(#|$) (.*) = Everything (#|$) = commen...

How to parse angular values using regular expressions

Hi, I have very little experience using regular expressions and I need to parse an angle value expressed as bearings, using regular expressions, example: "N45°20'15.3"E" Which represents: 45 degrees, 20 minutes with 15.3 seconds, located at the NE quadrant. The restrictions are: The first character can be "N" or "S" The last charac...

regex for parsing request parameters

Hello! I am looking for a single perl compatible regex that would parse strings of the form: param1=value1&...&param2=value2&... and extract values for param1 and param2 only. But param2 may precede param1 There may be no param1 or param2 param1 or param2 (or both) may have empty values, i.e. param1=&... ...

Python Regex combined with string substitution?

I'm wondering if its possible to use string substitution along with the python re module? For example I'm using optparse and have a variable named options.hostname which will change each time the user executes the script. I have the following regex matching 3 strings in each line of the log file. match = re.search (r'^\[(\d+)\] (SER...

How can I append instead of replace text during a search-and-replace with Perl?

I am trying to do search-and-replace using a regex in Perl. The text I am searching for is: <space>Number<space>NumberNumberNumber and I want to replace it with: <space>Number<space>NumberNumberNumberI I have the following regex which works in finding the string: \s[0-9]\s[0-9[0-9][0-9] But what do I do about replacing the s...

Python Regex Search And Replace

I'm not new to Python but a complete newbie with regular expressions (on my to do list) I am trying to use python re to convert a string such as [Hollywood Holt](http://www.hollywoodholt.com) to <a href="http://www.hollywoodholt.com"&gt;Hollywood Holt</a> and a string like *Hello world* to <strong>Hello world</strong> ...

Strip out extra spaces when there is more than one in a row

I am after a Regex expression that will strip out white spaces when there is two or more repeated, leaving just one space behind. For example this line The cow jumped over the moon which has multiple spaces separating the words in some cases would become The cow jumped over the moon ...

PHP: how to load file from different server as string?

I am trying to load an XML file from a different domain name as a string. All I want is an array of the text within the < title >< /title > tags of the xml file, so I am thinking since I am using php4 the easiest way would be to do a regex on it to get them. Can someone explain how to load the XML as a string? Thanks! ...

Regex matching in ColdFusion OR condition

I am attempting to write a CF component that will parse wikiCreole text. I am having trouble getting the correct matches with some of my regular expression though. I feel like if I can just get my head around the first one the rest will just click. Here is an example: The following is sample input: You can make things **bold** or //...

Postgresql query to update fields using a regular expression

I have the following data in my "Street_Address_1" column: 123 Main Street Using Postgresql, how would I write a query to update the "Street_Name" column in my Address table? In other words, "Street_Name" is blank and I'd like to populate it with the street name value contained in the "Street_Address_1" column. From what I can ...

Best Regular Expression for Email Format Validation with ASP.NET 3.5 Validation

I've used both of the following Regular Expressions for testing for a valid email expression with ASP.NET validation controls. I was wondering which is the better expression from a performance standpoint, or if someone has better one. - \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* - ^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\...

How do I use a regular expression to add linefeeds?

I have a really long string. I would like to add a linefeed every 80 characters. Is there a regular expression replacement pattern I can use to insert "\r\n" every 80 characters? I am using C# if that matters. I would like to avoid using a loop. I don't need to worry about being in the middle of a word. I just want to insert a linefeed...

Can you pass a dictionary when replacing strings in Python?

In PHP, you have preg_replace($patterns, $replacements, $string), where you can make all your substitutions at once by passing in an array of patterns and replacements. What is the equivalent in Python? I noticed that the string and re functions replace() and sub() don't take dictionaries... Edited to clarify based on a comment by ric...

Matching arbitrary number of words in PCRE regex into strings

Hello, I am using PCRE for some regex parsing and I need to search a string for words in a specific pattern (let's say all words in a string of words separated by commas) and put them into a string vector. How would I go about doing that? ...

Your Language Regex match full name "last, first middle1 middle2 suffix"

Spent me 3 hours to get a good regex finished for parsing these 3 main possible situations. Redden, Taylor Captain Hasting Jr. Redden, Taylor Hasting Jr. Redden, Taylor Hasting full, l, f, m1, m2, s = /your_regex_here/.match("Redden, Taylor Captain Hasting Jr.").to_a I want to see what other possible answers there are beside min...

How to match a string of a certain length with a regex

For a project of mine, I'm trying to implement a small part of the BitTorrent protocol, which can be found here. Specifically, I want to use the "Bencoding" part of it, which is a way to safely encode data for transfer over a socket. The format is as follows: 8:a string => "a string" i1234e => 1234 l1:a1:be => ['a', 'b'] d1:a1:b3:one3:t...

Tilde operator in Regular expressions

Hi guys, I want to know what's the meaning of tilde operator in regular expressions. I have this statement: if (!preg_match('~^\d{10}$~', $_POST['isbn'])) { $warnings[] = 'ISBN should be 10 digits'; } I found this document explaining what tilde means: ~ It said that =~ is a perl operator that means run this variable against this...

Matching order in PCRE

Hello, How can I set which order to match things in a PCRE regular expression? I have a dynamic regular expression that a user can supply that is used to extract two values from a string and stores them in two strings. However, there are cases where the two values can be in the string in reverse order, so the first (\w+) or whatever ne...