regex

Why won't this standard Reg Ex work in PHP's ereg function

I am a bit of a newbie to Reg Ex and don't fully understand the difference between the different flavors. However, I have a basic Reg Ex that works when I try it via the UNIX system (vi and grep) but not when I try to to use it in PHP's ereg functions. I suspect there is something different about the PHP ereg function that is making this...

Need help with extracting data with PHP Regular Expressions

I'm having trouble capturing this data: <tr> <td><span class="bodytext"><b>Contact:</b><b></b></span><span style='font-size:10.0pt;font-family:Verdana; mso-bidi-font-family:Arial'><b> </b> <span class="bodytext">John Doe</span> </span></td> </tr> ...

Python, Regular Expression Postcode search

Hi Guys, I am trying to use regular expressions to find a UK postcode within a string. I have got the regular expression working inside RegexBuddy, see below: \b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\b I have a bunch of addresses and want to grab the postcode from them, example below: 123 Some Road Name Town, City County...

Regular Expressions Ignore Case in search but not replace

In C#, I want to be able to generically replace text, ignoring case in the search but not in the replace (kind of?). Here is an example: I have a list that looks like this: Site -> Place Stuff -> Things etc... Then I want to call ConvertMyString("Site") and have it return "Place". So far I have this working, BUT... If I call Conv...

How do I create a regex to ensure a word is made up only of given single letters and letter groups?

I'm trying to create a Regex usuable in C# that will allow me to take a list of single letters and/or letter groups and ensure that a word is only comprised of items from that list. For instance: 'a' would match 'a', 'aa', 'aaa', but not 'ab' 'a b' would match 'a', 'ab', 'abba', 'b', but not 'abc' 'a b abc' would match 'a', 'ab', 'abc'...

C# Named parameters to a string that replace to the parameter values

Hi, I want in a good performance way (I hope) replace a named parameter in my string to a named parameter from code, example, my string: "Hi {name}, do you like milk?" How could I replace the {name} by code, Regular expressions? To expensive? Which way do you recommend? How do they in example NHibernates HQL to replace :my_param to ...

regular expression for finding parts of a string within another

I have two strings: the first's value is "catdog" and the second's is "got". I'm trying to find a regex that tells me if the letters for "got" are in "catdog". I'm particularly looking to avoid the case where there are duplicate letters. For example, I know "got" is a match, however "gott" is not a match because there are not two "t" ...

RegEx and matching codes right to left

Stuggling a little bit with the RegEx, I've got 4 codes in a string CODE4:CODE3:CODE2:CODE1 each code is optional apart from CODE1 So I could have ab:bc:de:fg or bc::fg of ab:::fg In each case of the above CODE1 = fg dnd for the dear life of me I can't work out the RegEX Would be easy to do as a standard string parse, but unfor...

PHP Regular Expression Question

Hi! I have a situation in which I parse a body of text and replace certain phrases with links. I then need to re-parse the string to replace a second set of phrases with links. The problem arises at this point, where certain words or phrases in the second set can be substrings of phrases already replaced in the first pass. Example: The...

How can I replace strings in a text in Java?

In a project we have text files looking like this: mv A, R3 mv R2, B mv R1, R3 mv B, R4 add A, R1 add B, R1 add R1, R2 add R3, R3 add R21, X add R12, Y mv X, R2 I need to replace the strings according to the following, but I am looking for a more general solution. R1 => R2 R2 => R3 R3 => R1 R12 => R21 R21 => R12 I know I could d...

Please explain this Perl regular expression

$rowfetch =~ s/['-]//g; #All chars inside the [ ] will be filtered out. $rowfetch =~ m/(\w+), ?(.)/; printf $fh lc($2.$1); I got help building this regular expression yesterday, but I don't fully understand it.It takes a name like Parisi, Kenneth and prints out kparisiKnowns:s/ = substitutem/ = matchI tried searching for the rest...

Javascript - MultiLine RegExp: lastIndex stuck on newlines?

Some Context From Javascript: The Definitive Guide: When regexp is a global regular expression, however, exec() behaves in a slightly more complex way. It begins searching string at the character position specified by the lastIndex preperty of regexp. When it finds a match, it sets lastIndex to the position of the first character ...

Implementing parser for escape sequences

I'm want to parse a custom string format that is persisting an object graphs state. This is ASP.Net scenario and I wanted something easy to use on the client (javascript) and server (c#). I have a format something like {Name1|Value1|Value2|...|ValueN}{Name2|Value1|...}{...}{NameN|...}. In this format I have 3 delimiters, {, }, and |. Fu...

Converting a MySQL .DMP file to a .SQL File for MS Sql Server 2005

I'm at square one on a project that will need to repeatedly import data from MySQL *.dmp files into an existing Sql Server database. I am looking for guidance in the form of an existing tool, framework, or, barring pre-existing solutions, suggestions for how to proceed. My first thought is to read the dmp file in as text and perform so...

How to get xp_pcre to run on a 64 bit system?

For many years we have been using xp_pcre for regular expressions in sql server: xp_pcre - Regular Expressions in T-SQL I've just migrated to a new 64 bit vista development machine and have installed xp pcre. Unfortunately when i try to use the sprocs I get the following error: Could not load the DLL xp_pcre.dll, or one of the DLLs it...

Need to re-format phone number entries in a PHP Formmail script

I have a simple text field for "Phone Number" in a contact form on a client's website. The formmail script returns whatever the user types into the field. For example, they'll receive "000-000-0000", "0000000000", (000) 000-000, etc. The client would like to receive all phone numbers in this form: 000-000-0000. Can someone provide a simp...

Python and regex question, extract float/double value

How do I extract a double value from a string using regex. import re pattr = re.compile('??????????????') x = pattr.match("4.5") ...

How can I use PHP to obfuscate email addresses so they are not easily harvested by spammers?

I'm programming in PHP and would like to create web pages which have email addresses that are easily read by humans but not easily harvested by spammers. The email addresses are coming from user input, and I think I can identify an address by using a regular expression, but I'm not clear exactly how I should replace the email addresses ...

Phone numbers to links in Python

I'm working a piece of code to turn phone numbers into links for mobile phone - I've got it but it feels really dirty. import re from string import digits PHONE_RE = re.compile('([(]{0,1}[2-9]\d{2}[)]{0,1}[-_. ]{0,1}[2-9]\d{2}[-_. ]{0,1}\d{4})') def numbers2links(s): result = "" last_match_index = 0 for match in PHONE_RE.f...

Where can I find a collection regular expression exercises for Perl?

I learned a lot of Perl RegEx syntax rules, but probably the only way to actually be able to write them is to do a bunch of 'RegEx' related exercises. I looked over the other "Learn RegEx" threads on StackOverflow, but haven't found anything similar. Is there any collection of such exercises? In form of book, HTML, with/without answers...