tags:

views:

170

answers:

6

This code is being used to parse email, it's stored as a table in a mySQL database. I believe it's PHP code. What does the (.+) do?

/A new order has been successfully placed through(.+)Name:(.+)Company:(.+)Email:(.+)Address 1(.+)Order ID:(.+)Date:(.+)Payment Type:(.+)Order Status:(\s*)Accepted(.*)\n(.+)\$([\d\.]+)\s+X/si

Thanks, super-brainiacs!

+6  A: 

That looks like a regular expression match. The (.+) parts are 'wildcard' captures.

This can be run against a string and the necessary information can be extracted. In most cases this string is language independent.

Just a few notes:

/si at the end means 'case insensitve' and '. match all' (means . will match everything including \n (which it normally does not))

The captures ((.+)) can be referenced after matching as $# in your average regex enabled language (where # is the order the (.+) appears in your regex string.

EDIT: You've updated your question so as an example, the section Name:(.+)Company:(.+) will match Name:Some random set of characters Company: Some more random characters where 'Some random set of characters' and 'Some more random characters' are extracted into variables $1 and $2 (because they are first and second in the order in your regex).

Matt S
+2  A: 

That's a regex pattern. The relevant PHP documentation starts here: PCRE (Perl-Compatible Regular Expression) Introduction

Each .+ is a placeholder for "any character, one or more times". The parentheses around it makes it so that anything matched by that placeholder is "captured", so that it can be used later (in your case, to store it into the database).

Chad Birch
+1  A: 

It's a regular expression, the (.+) means match any character once, or many times. See here for a handy reference, and here for a tool to test your regex expressions.

soulBit
A: 

It seems to be a dirty regex to verify that there are effectively the substrings 'Name', 'Company' etc... , the (.+) pattern allowing to catch the value of each 'field', in fact, here it catches everything around these substrings.

I think it's an argument for the php function ereg();

dader51
A: 

its a wildcard character. It . means single character and + means combination of specified character. like [a-zA-Z+] means combination of characters range from a-z A-Z and [a-z+]. means one character after a-z

Rahul
I think you meant `[a-zA-Z]+` and `[a-z]+`.
Alan Moore
A: 

The (.+) is a wildcard written in PCRE (regular expression).

Tech163