Remove anything after space in the same line – Regular Expressions

For example you have an SQL query like this

create table ipn_trans(
id int not null primary key auto_increment, 
txn_type varchar(100),
charset varchar(20),
custom varchar(255)

You want to create variables for each of the field. The first think you want to do is remove anything after the variable name. Use the following regular expression to achieve in in TextMate on Lion OSX.

 .+ [ there are three character here, first is space, then dot then +.]

Space character mean start the match with a space character anywhere in the line
. mean any character
+ means one or more of the previous character

The same should work in Visual Studio (they have regular expression too) but it is a bit buggy.

For example if you use the above regex to find one element and then the other, In Textmat, after finding first match it goes to the next in the remaining available text. In visual studio clicking next take you inside the same highlighted text which has another space character.

Other regular expression patterns in TextMate

$(.M)+    [the sentence must start with $ followed by any character. 2nd character must be M
This entry was posted in Software Development and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s